Skip to content

Instantly share code, notes, and snippets.

@dadatuputi
Forked from dschep/raspbian-python3.6.rst
Last active January 4, 2019 12:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dadatuputi/5e0c999b6d2ab8fcf5331c5ac177a486 to your computer and use it in GitHub Desktop.
Save dadatuputi/5e0c999b6d2ab8fcf5331c5ac177a486 to your computer and use it in GitHub Desktop.
Installing Python 3.5 on Raspbian

Installing Python 3.5 on Raspbian

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.

  1. 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 of libdb5.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
  1. 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

  1. 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

@tictag
Copy link

tictag commented Jan 8, 2018

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 I make -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 the make 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?

@polhomarkho
Copy link

@tictag Hi

I don't know if you solved your issue, but you should just clean your Python-3.6.4 folder, extract it again from the tar.xz and start again. Maybe it's because of the fact that you changed the Makefile ?
I'm currently building the exact same version of python and it's building OK so it should work for you too.

@sebasmano25
Copy link

@tictag Hi, Did you solve the problem? Because I can't install Python-3.5.2 , -3.5.3, and I have your same problem, and I don't know what to do to make Python works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment