Installing Python 3.6 on Raspbian
As of January 2018, Raspbian does not yet include the latest Python release, Python 3.6. This means we will have to build it ourselves, and here is how to do it. There is also an ansible role attached that automates it all for you.
Install the required build-tools (some might already be installed on your system).
$ sudo apt-get update $ sudo apt-get 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
If one of the packages cannot be found, try a newer version number (e.g.
Download and install Python 3.6. When downloading the source code, select the most recent release of Python 3.6, available on the official site. Adjust the file names accordingly.
$ wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz $ tar xf Python-3.6.5.tar.xz $ cd Python-3.6.5 $ ./configure $ make $ sudo make altinstall
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.6.5 $ rm Python-3.6.5.tar.xz $ sudo apt-get --purge remove build-essential tk-dev $ sudo apt-get --purge remove libncurses5-dev libncursesw5-dev libreadline6-dev $ sudo apt-get --purge remove libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev $ sudo apt-get --purge remove 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
@bastisawesome thanks for the reply. I've since decided it doesn't matter for me-- happy to leave 2.7 where it is and to make sure my scripts run the Python I want them to. Using virtualenvs solves most of the issues I was having.
@talderson1, I wouldn't want to actually remove Python 2. Keeping the system small isn't a priority for me (need GB for images and other data) and anyway the sweet spot for SD card pricing seems to be going up and up: fast 16GB cards are <$10 these days.