Skip to content

Instantly share code, notes, and snippets.

@amaork
Forked from BMeu/raspbian-python3.5.rst
Last active October 12, 2017 03:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amaork/ffa078a2fb55560052f07829c336f6b4 to your computer and use it in GitHub Desktop.
Save amaork/ffa078a2fb55560052f07829c336f6b4 to your computer and use it in GitHub Desktop.
Installing Python 3.5 on Raspbian

Installing Python 3.5 on Raspbian

As of October 2016, Raspbian does not yet include the latest Python release, 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).

    $ sudo apt-get update
    $ sudo apt-get install build-essential tk-dev
    $ sudo apt-get install libncurses5-dev libncursesw5-dev libreadline6-dev
    $ sudo apt-get install libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev
    $ sudo apt-get install libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev

    If one of the packages cannot be found, try a newer version number (e.g. libdb5.4-dev instead of libdb5.3-dev).

  2. 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 zxvf Python-3.5.3.tgz
    $ cd Python-3.5.3
    $ ./configure --prefix=/usr/local/opt/python-3.5.3 --enable-shared
    $ make
    $ sudo make install
  3. Make the compiled binaries globally available.

    $ sudo ln -s /usr/local/opt/python-3.5.3/bin/pydoc3.5 /usr/bin/pydoc3.5
    $ sudo ln -s /usr/local/opt/python-3.5.3/bin/python3.5 /usr/bin/python3.5
    $ sudo ln -s /usr/local/opt/python-3.5.3/bin/python3.5m /usr/bin/python3.5m
    $ sudo ln -s /usr/local/opt/python-3.5.3/bin/pyvenv-3.5 /usr/bin/pyvenv-3.5
    $ sudo ln -s /usr/local/opt/python-3.5.3/bin/pip3.5 /usr/bin/pip3.5
    $ sudo echo /usr/local/opt/python-3.5.3/lib > /tmp/python3.5.3.conf
    $ sudo mv /tmp/python3.5.3.conf /etc/ld.so.conf.d/
    $ sudo ldconfig

    You should now have a fully working Python 3.5 installation on your Raspberry Pi!

  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-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/

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