Skip to content

Instantly share code, notes, and snippets.

Created October 12, 2016 19:16
Show Gist options
  • Save BMeu/af107b1f3d7cf1a2507c9c6429367a3b to your computer and use it in GitHub Desktop.
Save BMeu/af107b1f3d7cf1a2507c9c6429367a3b 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
    $ tar zxvf Python-3.5.2.tgz
    $ cd Python-3.5.2
    $ ./configure --prefix=/usr/local/opt/python-3.5.2
    $ make
    $ sudo make install
  3. Make the compiled binaries globally available.

    $ sudo ln -s /usr/local/opt/python-3.5.2/bin/pydoc3.5 /usr/bin/pydoc3.5
    $ sudo ln -s /usr/local/opt/python-3.5.2/bin/python3.5 /usr/bin/python3.5
    $ sudo ln -s /usr/local/opt/python-3.5.2/bin/python3.5m /usr/bin/python3.5m
    $ sudo ln -s /usr/local/opt/python-3.5.2/bin/pyvenv-3.5 /usr/bin/pyvenv-3.5
    $ sudo ln -s /usr/local/opt/python-3.5.2/bin/pip3.5 /usr/bin/pip3.5

    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.2
    $ rm Python-3.5.2.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:

Copy link

dschep commented Jan 9, 2017

I've forked and updated this for Python 3.6 (and use make altinstall and the default prefix) here:

Copy link

petonic commented May 23, 2017

In step 2, for the first make command, use make -j 4 instead. This directs make to use 4 threads instead of being single threaded. It will reduce the build time significantly.

Copy link

SeppPenner commented Jul 3, 2018

I've done an updated version for 3.6.0, 3.6.4 and most recently for 3.7.0. However, 3.7.0 throws the errors:

rm /usr/local/lib/python3.7/lib-dynload/
rm -r /usr/local/lib/python3.7/lib-dynload/__pycache__
/usr/bin/install -c -m 644 ./Misc/ \
if test "xupgrade" != "xno"  ; then \
        case upgrade in \
                upgrade) ensurepip="--altinstall --upgrade" ;; \
                install|*) ensurepip="--altinstall" ;; \
        esac; \
         ./python -E -m ensurepip \
                $ensurepip --root=/ ; \
Traceback (most recent call last):
  File "/home/pi/Python-3.7.0/Lib/", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/pi/Python-3.7.0/Lib/", line 85, in _run_code
    exec(code, run_globals)
  File "/home/pi/Python-3.7.0/Lib/ensurepip/", line 5, in <module>
  File "/home/pi/Python-3.7.0/Lib/ensurepip/", line 204, in _main
  File "/home/pi/Python-3.7.0/Lib/ensurepip/", line 117, in _bootstrap
    return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
  File "/home/pi/Python-3.7.0/Lib/ensurepip/", line 27, in _run_pip
    import pip._internal
  File "/tmp/tmpzno7ofej/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/", line 42, in <module>
  File "/tmp/tmpzno7ofej/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/", line 16, in <module>
  File "/tmp/tmpzno7ofej/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/", line 25, in <module>
  File "/tmp/tmpzno7ofej/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/", line 39, in <module>
  File "/tmp/tmpzno7ofej/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/utils/", line 3, in <module>
  File "/home/pi/Python-3.7.0/Lib/ctypes/", line 7, in <module>
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
Makefile:1132: die Regel ¼r Ziel âaltinstallâ scheiterte
make: *** [altinstall] Fehler 1

Does anyone maybe have an idea where this comes from?

Copy link

How do you run the idle after it is installed

Copy link

I followed your instructions step by step.
Now i have python3.5 installed but i only can execute python3.5 by using the absolut path.
When I'm in the dir "usr/local/opt/python-3.5.2/bin" and try to execute python by using "sudo python3.5" it throws the error "command not found".
Also pip3.5 is not located at this dir.
The symbolic links are red and dont work.

Did i miss something here?
Thanks for help!


change the line make to
$ make -j 4 altinstall

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