As of June 2017, Raspbian does not yet include Python 3.5. This means we will have to build it ourselves, and here is how to do it.
- Install the required build-tools (some might already be installed on your system). If one of the packages cannot be found, try a newer version number (e.g.
libdb5.4-dev
instead oflibdb5.3-dev
).
$ sudo apt update
$ sudo apt install build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev
- Download and install Python 3.5. When downloading the source code, select the most recent release of Python 3.5, available on the official site. Adjust the file names accordingly.
$ wget https://www.python.org/ftp/python/3.5.3/Python-3.5.3.tgz
$ tar xf Python-3.5.3.tgz
$ cd Python-3.5.3
$ ./configure
$ make -s
$ sudo make altinstall
Note: Here is an explanation of the difference between 'install' and 'altinstall' in the last command above.
You may change the ./configure
command above to have make
perform some compilation optmizations. This will add a significant amount of time to your build - over an hour in my case - but if you need high performance from your pi it's worth enabling it:
$ ./configure --enable-optimizations
In addition, you can tell make
to use all cores during build, although when I used this command I experienced a documented bug:
$ make -s -j 4
- Optionally: Delete the source code and uninstall the previously installed packages. When uninstalling the packages, make sure you only remove those that were not previously installed on your system. Also, remember to adjust version numbers if necesarry.
$ sudo rm -r Python-3.5.3
$ rm Python-3.5.3.tgz
$ sudo apt purge build-essential tk-dev
$ sudo apt purge libncurses5-dev libncursesw5-dev libreadline6-dev
$ sudo apt purge libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev
$ sudo apt purge libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev
$ sudo apt-get autoremove
$ sudo apt-get clean
This guide is pretty much taken from the following tutorial: https://liudr.wordpress.com/2016/02/04/install-python-on-raspberry-pi-or-debian/ and https://gist.github.com/BMeu/af107b1f3d7cf1a2507c9c6429367a3b
elBradford,
I'm really new to software development and I've tried to follow these instructions to compile Python-3.6.4 from the official site. The
./configure --enable-optimizations
command seems to work fine but when Imake -s -j 4
my RPi3 (Jessie) just seems to run the configure command again and again (and again...). I've left it running for 48 hours but it never ends. When I run themake
command I'm expecting it to actually compile the source code, not just keep checking it.I've uploaded a screencast here. It starts just after the
./configure --enable-optimizations
command and I end it with CTRL-C. Any idea what I'm doing wrong?