Learning Python with Raspberry Pi

If you’ve been round here for any length of time, you’ve probably heard mention of Alex Bradbury. Alex is currently polishing off his PhD thesis at the Computer Lab at the University of Cambridge, and he’s been involved with the Raspberry Pi project as a volunteer from our very early days, back when all we had was alpha development boards. Alex is responsible for building and releasing Raspberry Pi’s Raspbian OS images, and maintaining our Debian repository in his (limited) spare time.

He’s somehow also found the time to write a book with Linux Voice‘s Ben Everard.

Learning Python with Raspberry Pi doesn’t presuppose any computing knowledge, and takes you from a standing start through variables, loops and functions, 3D graphical programming, building games, networking, scripting, interfacing with hardware…and, of course, Minecraft. There’s much more besides: if you work your way through the whole book you’ll be building robots and alarm systems; manipulating sound and video; and learning how to test and debug the Bradbury and Everard way.

As well as what you’ll find in the book, Alex and Ben have made a large code repository available to complement the information and instructions in Learning Python with Raspberry Pi: you’ll be able to download what you need free of charge.

Alex says:

Ever since the introduction of the Raspberry Pi, Python has been touted (with good reason) as the language of choice for anyone wanting to program on the device. Reasonable people can disagree on the ultimate reasons for Python’s success, but I think we can all recognise what an asset its large and friendly community is, as well as the value of its extensive collection of high quality libraries for helping to solve almost any programming task.

Learning Python with Raspberry Pi aims to teach the reader the Python they need to make their Raspberry Pi project ideas a reality. We give lots of examples in the sort of areas likely to be of interest to the Pi community – including physical computing, audio and video, 3d graphics, Minecraft programming, and games.  Another important aspect for us is that every chapter ends with a whole host of ideas and pointers on what you’re now able to do given what you’ve just learnt. Python is the single most useful language to know for the Raspberry Pi, and I like to think that with Learning Python with Raspberry Pi, we’ve managed to produce an entertaining and educational introduction to it. Hopefully you agree!

Learning Python with Raspberry Pi is available from Amazon, and from a good book shop near you: we hope to be stocking it in the Swag Store soon too.

 

 

40 comments

Avatar

Nice. I think I might have to check this out.

Avatar

is there no available PDF version???

Avatar

BUY IT!

I have had the book for a while now and it is awesome. What other beginner book teaches you 3D programming?! It is written in an eloquent manner and is easy to follow and understand.

Not to mention it starts with Turtle ;-)

Superb work Alex and Ben!

The Raspberry Pi Guy

Avatar

I have a 6yr old son who is itching to play with his Pi laptop(Pi with a Moto Lapdock), but I’m trying to encourage him to learn to read first. My question is, what age level is this guide geared for?

liz

Your son’s a bit young for this – kids 13 and up will be fine on their own (of course, there will be plenty of kids much younger than that who will fly with it). Have you looked into Carrie Anne’s Adventures in Raspberry Pi? He’ll still need your supervision, but he’ll get much more out of it.

Avatar

Adventures in Raspberry Pi is excellent. I can additionally recommend Chris Roffey’s series of Python books: http://www.amazon.co.uk/Chris-Roffey/e/B009EBQXV6/

Avatar

What about more mature audiences, such as me (47 yo), who left programming some 18 years ago and want to dip in again. I have this book, and Learn Python the Hard Way. Any title you’d recommend?

Thx
Miguel

Avatar

I of course like to think you’ll get a lot out of Learning Python with Raspberry Pi. Learn Python the Hard Way is also excellent if it matches your learning style. For books beyond that, I think you’re best using something like Learning Python with Raspberry Pi or Learning Python the Hard Way to get going, then seeing where you want to go from there. You might find you’re happy going with tutorials and documentation online, or perhaps you have a certain interest in a class of applications (web development, machine learning, who knows?) which might point to what you should look for next.

Avatar

I’m with you,sir! I used to program back in my teems (BASIC, Pascal, some C), but have not done anything useful in the last 20+ years. I bought the Pi a few months ago and have been having nothing but fun. Time to get into some serious learning, though. I bought the book yesterday and cannot wait for it to arrive. I have been itching to get back into programming, but was never sure where to start. This looks to be a good way!

Avatar

Added to my amazon wishlist! Does this cover Python 2, 3 or both?

Avatar

We chose to focus just on Python 3. Anyone who studies the book and needs to use Python 2 (e.g. 2.7 or 2.6) for some reason shouldn’t have much trouble though.

Avatar

One reason might be that 2.x is what the Foundation is recommending and targeting most of its educational efforts toward because of the large body of existing software that is incompatible with 3.x in key ways without a humongous, guaranteed bug-infested reengineering effort.

Another reason is that 3.x seems to be one of those right-flank marches that some otherwise-intelligent people order because of its assumed theoretical technical superiority, only to watch the rest of the parade continue down the boulevard where the TV crews, audience, and others keenly interested in parades have been spending a very long time waiting. IBM’s misadventure with its shift from the open Industry Standard Architecture to its proprietary MicroChannel Architecture, vs. the industry’s response with Extended Industry Standard Architecture, comes to mind. The bickering fragmentation between Unix camps while Microsoft expanded into the void created is another example.

“Better” is often the enemy of “Good Enough”, and that’s precisely where things stand with Python, among other software development tools at similar crossroads. Given how many advances have been made in automated software development tools that make transitions painless, it’s difficult to believe it’s actually the year 2014 with continuing misguided declarations that “The King is dead. Long live the King!” when it comes to newer versions of software tools that are incompatible with their very popular (and increasing) older siblings.

Avatar

Jim, the Foundation does not have an official stance on Python 2 vs Python 3 in favour of Python 2. Eben has stated that he likes the fact that you can omit the parentheses in a Python 2 ‘hello world’. There’s a reason we ship both Python 2 and 3 on the Foundation’s Raspbian image. In fact, Python 3 seems to have particularly good uptake in the education community where obviously there aren’t the same legacy requirements you have in industry.

The community’s transition from Python 2 to Python 3 has been long and slow, but I think it’s clearly going in the Python 3 direction, after all – there will be no future Python 2.x feature release. There are some annoying exceptions, but I think Python 3 compatibility of common libraries is looking very good http://py3readiness.org/.

Avatar

Personally I’m in favour of pushing forward with Python 3. But work needs to be done on filling the gap and making the presence of two versions as painless as possible.

Avatar

Ordered. My 15 year-old daughter really wants to learn to code. I don’t know how she can have got all the way through the system as far as being half way through a year-early IT AS level at a grammar school without having done a single line of code.

Despite having learned and forgotten more programming languages than most IT people can name I think it’s safer for all concerned if she learns from a book!

Pi #2 is currently not being used…

Avatar

Can anyone recommend any good big projects to make in Python on the Pi? I’ve has a book sitting here ages collecting dust. It seems whenever I get into it I have to go back to PHP for work, and never have a good reason to finish off learning Python, despite really wanting to :(

Avatar

What are your interests? I think the best advice really is to come up with a project that will solve a problem you have. The motivation is much stronger, and often the design is much more straight-forward (you have a fixed problem to solve). If you’re totally totally stuck, have a flick through projects people post here or elsewhere (e.g. reddit’s /r/python), find one you think you could do better, then go away and do it.

Avatar

I tried to sit and ponder your first query about interests for a while. Eventually I came up with something potentially decent. 3D printing. I’ve got two of them (well…one and a half that’s currently being built). I’d love to have a pi under the hood, with a touchscreen display that will let me send commands to the printerboard via USB (a bit like pronterface but just the basic commands on a touch pad type thing). That could potentially be a cool project to try out :)

Avatar

Look into OctoPrint. Turns a RasPi into a 3D printer host with ability to send commands and monitor the printer over the internet.

Avatar

will there be a pdf version too?

Avatar

There are ebook versions.
For Kindle: $16.49 (Amazon USA), £ 11.39 (Amazon UK),
For B&N Nook: $16.49 (in USA)

Avatar

Hopefully there’ll be a PDF version on oreilly.com in the not too distant future. My publisher is chasing it up…

Avatar

This book is excellent – received copy last week. GCSE students got straight in and we’re using it to extend Python understanding via Pis and standard PCs. Also great as a reference book. I’m thinking of getting next year’s students to purchase their own copy with a Pi to get ahead over the summer holidays. Really well written and interesting code to get students into.

Avatar

I’m jealous, this book is already bestseller in 3 different categories on Amazon. *Sulk* mine has never been a bestseller!

It is a fantastic book!

Avatar

Ask Amazon to create more categories?! ;)

Avatar

Ordered!

Been looking for a book like this but never seem to find the right one.

Avatar

A darn decent book on Python. I got to peruse it while running The MagPi stand at Bristol Digimakers. Chatted to Ben too. Darn decent chap as well.

Recommended reading.

Avatar

ordered, now got to wait and think of a project
does it cover pi camera and python?
thinking some form of robot which can map a maze and work it out?
do you think the book is suitable for someone who has passed the half century ?

Avatar

It covers use of the Pi Camera, though sadly the excellent python-picamera module by Dave Jones wasn’t around when that chapter was written, so it involves shelling out to the raspistill/raspivid binaries instead.

We get you started with using OpenCV for computer vision, which should be useful to your planned robotics project. I don’t think there’s any upper age limit on who would benefit from the book!

Avatar

Shame about python-picamera but that’s the way things go. It’s like the tragedy of Carrie Anne missing out a mention of Pi Weekly in her Adventures book.

We’re writing some learning material (for all ages), some of which involve the camera module and we’ll use python-picamera where suitable. These will start to appear when we launch the new website.

Avatar

I received this soon after it’s release, and finally began digging in this week (yay for holiday leave!).

For anyone currently playing with Turtle, or perhaps considering it for the classroom, additional documentation for the module can be found here.

Since reading the Turtle chapters and implementing some of the features from the Python wiki, I’ve been thinking about the possibility of driving the turtle with a 360 controller and having it drop patterns based on different button presses. A little project for this weekend perhaps? ;-)

Really looking forward to the PyGame and PyGL chapters.

Go buy the book. It’s great!

Avatar

Hello,

Thank you for taking the time to implement an instructional book for those completely new to the Python language and to programming in general.

I plan to co learn python for turn based games and function based projects with my family including younger children…

Does this book rely on heavy mathematics to learn the Python language or does it instead teach the language in a way that does not hinder those who do not have a keen understanding of mathematics?

I do realize that math, even at its barest of levels, is an important part of programming however I also realize that programming does not revolve solely around it.

So far, I have only found one source that teaches “the fun” aspect of programming by teaching the audience to make text based games.

I was only able to preview the first few programming pages of your book on Amazon and they (thankfully) did not begin with writing dining-tip calculators and turning Python into a glorified calculator so I very much look forward to your reply and that of others that have read this book.

Sincerely,
Gandar
US

Avatar

Hi Gandar. There is no heavy dependency on mathematics at all. You can’t completely escape from numbers, because things like writing a game (which is of course a really popular aim for people learning to program) will involve at least some manipulation of numbers for distance or collision calculations and the like, but that’s fairly light and we try to make the explanations as intuitive as possible. By necessity, the chapter on 3d graphics (OpenGL ES) ends up being a little more math-heavy. But you’re completely free to pick and choose which of the later chapters you want to dig in to. Hope that helps!

Avatar

ASB,

Thank you for taking the time to reply. I have just placed my order and eagerly look forward to getting into it with the family.

I will post and update when we get into it so that others new to the language in the community can see.

Gandar

Avatar

Awesome book for starting out, it’s one of the two I’m using to learn from at the current time.

easy to understand even for older newbies like me!

Avatar

Have you any plans to publish a Braille version?

Dave.

Avatar

hi
i want to connect msp430 to raspberry pi to spi communication and i want monitor on pi digital to analog converter how to do this plz help me.
thank you

Avatar

Please ask in the forums, thanks

Avatar

In my kindle book, in the section “using Functions and Methods to Structure Code”, the area of a circle is declared to be 2*pi*the radius. In actuality, it should be pi*the radius squared.

Avatar

My local university is using this book to teach python on the pi computer (?). It sounds perfect for my 10th grader that wants to learn programming. Do the concepts and programming knowledge learned in this course transfer easily to programming on pcs and macs?

Thank you.

Leave a Comment

Comments are closed