Short Tutorial : Raspbian + Python3.4 + RPi.GPIO

12-03-2015 22:57 by depado

You know what bothers me everytime I get back on a Debian-like system ? The Python version. I mean... Come on, it's 2015, let's switch to 3.4 ! So I wanted to do so on my Raspberry Pi (the first version) because I finally decided to improve my electronic skills. First thing I wanted to try are the GPIO. I know it works fine on the Python version installed on Raspbian by default. But I wanted to code in 3.4 so let's see how we can setup a Raspbian with Python 3.4 that can handles the GPIO !

Install and connect to your Raspbian

First of all, install Raspbian on your SD Card. Download Page - Tutorial to Install Raspbian on your SD Card
There is an automatic DHCP when Raspbian starts and SSH is now activated by default on the latest versions of Raspbian. So once your Raspberry is started, you may be able to get its IP address on your internet equipment web ui ( or something like that). If the web ui doesn't provide such information, you can run nmap to find out. nmap -sn The -sn flag is the ping flag and allows to find every equipment connected to your local network. Now get your Raspberry's IP and connect to it using ssh. For clarity purpose, on the following line, is just an example. ssh pi@ The password is raspberry. It's the default password and you should change it immediatly by the way.

Download dependencies

Now, you'll want to install Python 3.4, but you'll soon find out that you won't have pip installed unless you install the ssl libs before.

pi@raspberrypi ~ $ sudo apt-get update
pi@raspberrypi ~ $ sudo apt-get install libssl-dev openssl

That's right, pip needs SSL/TLS support and will complain like crazy if those libssl and openssl are not installed.

Download, Compile and Install Python 3.4

Finally, your wish to do a make and a make install has come true ! Let's download the latest Python version using wget, extract the archive, configure, make and make install. Compiling Python can take more than one hour on Raspberry, so be patient

pi@raspberrypi ~ $ wget https://www.python.org/ftp/python/3.4.3/Python-3.4.3.tar.xz
pi@raspberrypi ~ $ tar xvf Python-3.4.3.tar.xz
pi@raspberrypi ~ $ cd Python-3.4.3/
pi@raspberrypi ~ $ ./configure   # You can set a prefix here
pi@raspberrypi ~ $ make
pi@raspberrypi ~ $ sudo make install

Now that you waited for like an hour and thirty minutes, the latest python version is now installed.

Create a virtualenv and download the right libs

I'm pretty sure that if you want to download and compile the latest Python version, you also know what's a virtualenv. If not, here is a guide. But did you know that Python 3.4 comes with an integrated virtualenv ? It's called pyvenv-3.4. Once you have created a virtualenv (as described below) you'll need to install the RPi.GPIO package with pip. Here is the list of command lines that allows you to do that.

pi@raspberrypi ~ $ pyvenv-3.4 env
pi@raspberrypi ~ $ source env/bin/activate
# If (and only if) source doesn't work :
# pi@raspberrypi ~ $ . env/bin/activate
(env) pi@raspberrypi ~ $ pip install RPi.GPIO

Now you're ready !