Install git

$ sudo apt install git

Install Python build dependencies

Python includes a set of modules that it builds by linking to other popular open source projects. Many of those projects are included in Debian by default as executable programs, but the development files (headers, libraries) necessary to link them into Python are packaged separately and not included in a default Debian install.

Some of these libraries are actually required for the python build/install steps to complete successfully:

| Library                            | Python Module | Dev Package  |
| ---------------------------------- | ------------- | ------------ |
| https://www.zlib.net/              | `zlib`        | `zlib1g-dev` |
| https://www.sourceware.org/libffi/ | `_ctypes`     | `libffi-dev` |

The entries in the 'Dev Package' column are the names of packages containing the development files our python build needs.

Each of these 'dev' packages has a corresponding binary package that is probably already installed. So you're likely not going to be adding new pieces of software to your system by installing these. You're just installing the files necessary to compile new pieces of software (in our case a newer python) so that it can use them. (Also note that these 'dev' packages all have their corresponding binary packages as dependencies, so installing a dev package will ensure that its binary package is also installed.)

So let's install them:

sudo apt install zlib1g-dev libffi-dev

Next we have the OpenSSL library. Python considers OpenSSL optional, but you probably want it. For example, even using Python's package installation tools can run into trouble when fetching https urls if SSL/TLS support is missing.

| Library                  | Python Module | Dev Package |
| ------------------------ | ------------- | ----------- |
| https://www.openssl.org/ | `_ssl`        | `libssl-dev |

Let's install it:

sudo apt install libssl-dev

The next set of packages fall more in the 'optional' category:

| Library                                              | Python Module(s)              | Dev Package        |
| ---------------------------------------------------- | ----------------------------- | ------------------ |
| http://www.bzip.org/                                 | `_bz2`                        | `libbz2-dev`       |
| https://www.gnu.org/software/ncurses/                | `_curses` and `_curses_panel` | `libncursesw5-dev` |
| https://www.gnu.org.ua/software/gdbm/                | `_dbm` and `_gdbm`            | `libgdbm-dev`      |
| https://tukaani.org/xz/                              | `_lzma`                       | `liblzma-dev`      |
| https://www.sqlite.org/                              | `_sqlite3`                    | `libsqlite3-dev`   |
| https://www.tcl.tk/software/tcltk/                   | `_tkinter`                    | `tk-dev`           |
| https://github.com/karelzak/util-linux               | `_uuid`                       | `uuid-dev`         |
| https://tiswww.case.edu/php/chet/readline/rltop.html | `readline`                    | `libreadline-dev`  |

Python can build and install without these, and your applications might not need them. On the other hand, if you install them, the 'make' step shouldn't report any modules it was unable to build, and the binaries are already included in a default Debian install.

The command to copy-paste if you'd like to go ahead and install all of the above 'optional' packages is:

sudo apt install libbz2-dev libncursesw5-dev libgdbm-dev liblzma-dev libsqlite3-dev tk-dev uuid-dev libreadline-dev

Build and install python from source

  1. clone the python git repository.
$ git clone [email protected]:python/cpython.git
Cloning into 'cpython'...
[...]
Resolving deltas: 100% (592215/592215), done.
  1. Checkout the version you want to install (in this case, 3.7.2) using the git tag name.
$ cd cpython/
cpython$ git checkout v3.7.2
Note: checking out 'v3.7.2'.
[...]
HEAD is now at 9a3ffc0492... 3.7.2final
cpython$
  1. Choose an install prefix. That is, the path the compiled and linked project will be installed into. In this case I'll use $HOME/python/v3.7.2. I'm including the version number since I'll want to install other versions in the future, and keep them separate. Run the configure script with this path as the --prefix argument. (If you don't provide a --prefix argument, it will default to /usr/local).
cpython$ ./configure --prefix=$HOME/python/v3.7.2
[...]
checking for inflateCopy in -lz... yes
[...]
checking for openssl/ssl.h in /usr... yes
[...]

The configure script will check a bunch of things, many of which are unnecessary. The ones shown in the above output, though, can be considered necessary.

  1. Build python by running make. If we included the minimum set of dependencies necessary to build and install python, the output will tell you near the end what modules were not built:
cpython$ make
[...]
Python build finished successfully!
The necessary bits to build these optional modules were not found:
_bz2                  _curses               _curses_panel      
_dbm                  _gdbm                 _lzma              
_sqlite3              _tkinter              _uuid              
readline                                                       
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

The make output describes this as a list of 'optional' modules but again, at least for this particular version of python, it probably won't build and install successfully without the zlib, and _ctypes modules.

  1. Install python by running make install. We've already provided the install location back in the configure step. If your install location is a root-owned directory (e.g. /usr/local), prefix this command with sudo. Since in this case I'm installing to a user-owned directory, I don't want to do that.
cpython$ make install
Creating directory /home/python/v3.7.2/bin
Creating directory /home/python/v3.7.2/lib
[...]

  1. You should now have an executable you can run from the bin directory underneath the install prefix named python3. (Note that this installer doesn't put anything at bin/python; just bin/python3.)
HOME/python/v3.7.2/bin/python3
Python 3.7.2 (v3.7.2:9a3ffc0492, Mar 10 2019, 19:35:56) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
$
Answer from Charlie on Stack Exchange
🌐
Reddit
reddit.com › r/debian › installing python 3.7 on debian jessie
r/debian on Reddit: Installing Python 3.7 on Debian jessie
April 11, 2024 -

Hello guys,

I'm very struggling installing Python3.7 on a very old Debian distrib.

First, I cannot use a more recent version of debian, its a very old PC with a soft that cannot be upgraded so I'm stuck with Debian jessie.

The program I wrote need at least a Python 3.7 so I'm using a Docker image of debian jessie to build the application as standalone using Pyinstaller but I'm not able to go that far...

I'v followed some tutorials to do so like : https://kitabi.eu/blog/2019-06-26-python-install/ or https://jameskiefer.com/posts/installing-python-3.7-on-debian-8/

But I cant download packages with pip, I got a SSLError("Can't connect to HTTPS URL because the SSL module is not available")

What am I doing wrong ? Do you have some solutions ? Like an existing Docker image of debian jessie with python 3.7 already installed ? lol

Thanks in advance, I'm a bit desesperate at this point o7

Discussions

Python 3.7 on Debian 9 from package manager - Unix & Linux Stack Exchange
You can sometimes install newer software packages via the backports repository. However, it appears Python 3.7 is not available in backports ... You can also take the next Debian's package sources, and rebuild a backported package from those sources. More on unix.stackexchange.com
🌐 unix.stackexchange.com
linux - Install Python 3.7.x on Windows Subsytem Debian 9.6 - Stack Overflow
When attempting to update my Python version from 3.53 to 3.7 I run sudo apt-get install python3 but no upgrade is performed, I only see this message: python3 is already the newest version (3.5.3-1) More on stackoverflow.com
🌐 stackoverflow.com
Installing Python 3.7 on old Debian (jessie 8)
Did you build and install openssl as described in that guide? It might be easier to use a modern version of Debian and run the software that requires Debian 8 in VirtualBox. More on reddit.com
🌐 r/learnpython
9
7
April 11, 2024
Debian 10 Buster using Python 3.7
It would be useful to support this platform to expand the potential StackStorm user base by having native packaging and installation process for this distribution. The current stable version is Debian 10 Buster which provides Python3.7 only, no Python 3.6 packages are provided by Debian. More on github.com
🌐 github.com
13
January 17, 2020
🌐
GitHub
gist.github.com › j40903272 › a4b715b79b2e5aa74342fe995a1c1ef9
Install python3.7 · GitHub
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1 sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2 sudo update-alternatives --config python3 ... sudo apt-get install -y build-essential ...
🌐
Jameskiefer
jameskiefer.com › posts › installing-python-3.7-on-debian-8
Installing Python 3.7 on Debian 8 - James Kiefer
October 18, 2018 - pip3.7 install certifi sudo ln -s /usr/local/lib/python3.7/site-packages/certifi/cacert.pem /usr/local/ssl/cert.pem ... Thank you …. this suggestion was a god-send. ... I’m trying to build Python 3.7.3 on a Raspberry Pi.
🌐
Stack Exchange
unix.stackexchange.com › questions › 571022 › python-3-7-on-debian-9-from-package-manager
Python 3.7 on Debian 9 from package manager - Unix & Linux Stack Exchange
# Start by installing the packages necessary to build Python source: $ sudo apt update $ sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget # Download the latest release’s ...
🌐
Stack Overflow
stackoverflow.com › questions › 53354336 › install-python-3-7-x-on-windows-subsytem-debian-9-6
linux - Install Python 3.7.x on Windows Subsytem Debian 9.6 - Stack Overflow
... You'd have to either: 1) add the testing apt sources to get the latest python from Debian Testing; 2) Add the Python 3.7 ppa and install it from it (look here); 3) Download Python 3.7 source code by hand and compile it yourself.
Top answer
1 of 1
39

Install git

$ sudo apt install git

Install Python build dependencies

Python includes a set of modules that it builds by linking to other popular open source projects. Many of those projects are included in Debian by default as executable programs, but the development files (headers, libraries) necessary to link them into Python are packaged separately and not included in a default Debian install.

Some of these libraries are actually required for the python build/install steps to complete successfully:

| Library                            | Python Module | Dev Package  |
| ---------------------------------- | ------------- | ------------ |
| https://www.zlib.net/              | `zlib`        | `zlib1g-dev` |
| https://www.sourceware.org/libffi/ | `_ctypes`     | `libffi-dev` |

The entries in the 'Dev Package' column are the names of packages containing the development files our python build needs.

Each of these 'dev' packages has a corresponding binary package that is probably already installed. So you're likely not going to be adding new pieces of software to your system by installing these. You're just installing the files necessary to compile new pieces of software (in our case a newer python) so that it can use them. (Also note that these 'dev' packages all have their corresponding binary packages as dependencies, so installing a dev package will ensure that its binary package is also installed.)

So let's install them:

sudo apt install zlib1g-dev libffi-dev

Next we have the OpenSSL library. Python considers OpenSSL optional, but you probably want it. For example, even using Python's package installation tools can run into trouble when fetching https urls if SSL/TLS support is missing.

| Library                  | Python Module | Dev Package |
| ------------------------ | ------------- | ----------- |
| https://www.openssl.org/ | `_ssl`        | `libssl-dev |

Let's install it:

sudo apt install libssl-dev

The next set of packages fall more in the 'optional' category:

| Library                                              | Python Module(s)              | Dev Package        |
| ---------------------------------------------------- | ----------------------------- | ------------------ |
| http://www.bzip.org/                                 | `_bz2`                        | `libbz2-dev`       |
| https://www.gnu.org/software/ncurses/                | `_curses` and `_curses_panel` | `libncursesw5-dev` |
| https://www.gnu.org.ua/software/gdbm/                | `_dbm` and `_gdbm`            | `libgdbm-dev`      |
| https://tukaani.org/xz/                              | `_lzma`                       | `liblzma-dev`      |
| https://www.sqlite.org/                              | `_sqlite3`                    | `libsqlite3-dev`   |
| https://www.tcl.tk/software/tcltk/                   | `_tkinter`                    | `tk-dev`           |
| https://github.com/karelzak/util-linux               | `_uuid`                       | `uuid-dev`         |
| https://tiswww.case.edu/php/chet/readline/rltop.html | `readline`                    | `libreadline-dev`  |

Python can build and install without these, and your applications might not need them. On the other hand, if you install them, the 'make' step shouldn't report any modules it was unable to build, and the binaries are already included in a default Debian install.

The command to copy-paste if you'd like to go ahead and install all of the above 'optional' packages is:

sudo apt install libbz2-dev libncursesw5-dev libgdbm-dev liblzma-dev libsqlite3-dev tk-dev uuid-dev libreadline-dev

Build and install python from source

  1. clone the python git repository.
$ git clone [email protected]:python/cpython.git
Cloning into 'cpython'...
[...]
Resolving deltas: 100% (592215/592215), done.
  1. Checkout the version you want to install (in this case, 3.7.2) using the git tag name.
$ cd cpython/
cpython$ git checkout v3.7.2
Note: checking out 'v3.7.2'.
[...]
HEAD is now at 9a3ffc0492... 3.7.2final
cpython$
  1. Choose an install prefix. That is, the path the compiled and linked project will be installed into. In this case I'll use $HOME/python/v3.7.2. I'm including the version number since I'll want to install other versions in the future, and keep them separate. Run the configure script with this path as the --prefix argument. (If you don't provide a --prefix argument, it will default to /usr/local).
cpython$ ./configure --prefix=$HOME/python/v3.7.2
[...]
checking for inflateCopy in -lz... yes
[...]
checking for openssl/ssl.h in /usr... yes
[...]

The configure script will check a bunch of things, many of which are unnecessary. The ones shown in the above output, though, can be considered necessary.

  1. Build python by running make. If we included the minimum set of dependencies necessary to build and install python, the output will tell you near the end what modules were not built:
cpython$ make
[...]
Python build finished successfully!
The necessary bits to build these optional modules were not found:
_bz2                  _curses               _curses_panel      
_dbm                  _gdbm                 _lzma              
_sqlite3              _tkinter              _uuid              
readline                                                       
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

The make output describes this as a list of 'optional' modules but again, at least for this particular version of python, it probably won't build and install successfully without the zlib, and _ctypes modules.

  1. Install python by running make install. We've already provided the install location back in the configure step. If your install location is a root-owned directory (e.g. /usr/local), prefix this command with sudo. Since in this case I'm installing to a user-owned directory, I don't want to do that.
cpython$ make install
Creating directory /home/python/v3.7.2/bin
Creating directory /home/python/v3.7.2/lib
[...]

  1. You should now have an executable you can run from the bin directory underneath the install prefix named python3. (Note that this installer doesn't put anything at bin/python; just bin/python3.)
HOME/python/v3.7.2/bin/python3
Python 3.7.2 (v3.7.2:9a3ffc0492, Mar 10 2019, 19:35:56) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
$
Find elsewhere
🌐
Debian
wiki.debian.org › Python
Python - Debian Wiki
May 20, 2026 - Note that /usr/local/lib/pytho... --install-layout=deb option to the setup script while building a Debian package so that its installs files into /usr/ not /usr/local/. Python 2.7, 3.3, and 3.4 are multiarch aware....
🌐
Antonio's IT Blog
antonioyan.wordpress.com › 2020 › 08 › 18 › how-to-install-python-3-7-on-ubuntu-debian-and-linuxmint
How to Install Python 3.7 on Ubuntu, Debian and LinuxMint | Antonio's IT Blog
August 18, 2020 - sudo apt-get install wget ... libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev · Download Python using following command from python official site....
🌐
Python
python.org › downloads › release › python-370
Python Release Python 3.7.0 | Python.org
For 3.7.0, we provide two binary installer options for download. The default variant is 64-bit-only and works on macOS 10.9 (Mavericks) and later systems. We also continue to provide a 64-bit/32-bit variant that works on all versions of macOS from 10.6 (Snow Leopard) on.
🌐
Linux Today
linuxtoday.com › home › news
How To Install Python 3.7 on Debian 9 Stretch | Linux Today
June 22, 2021 - In this tutorial we will show you how to install Python 3.7 on Debian 9 Stretch, as well as some extra required by Python
🌐
Linode
linode.com › docs › guides › how-to-install-python-on-debian-10
How to Install Python 3 on Debian 10 | Linode Docs
February 12, 2021 - Python 3 is installed by default on Debian 10. This guide shows how to invoke Python 3 on Debian 10 and how to upgrade it from version 3.7 to 3.9.
🌐
Reddit
reddit.com › r/learnpython › installing python 3.7 on old debian (jessie 8)
r/learnpython on Reddit: Installing Python 3.7 on old Debian (jessie 8)
April 11, 2024 -

Hello guys,

I'm very struggling installing Python3.7 on a very old Debian distrib.

First, I cannot use a more recent version of debian, its a very old PC with a soft that cannot be upgraded so I'm stuck with Debian jessie.

The program I wrote need at least a Python 3.7 so I'm using a Docker image of debian jessie to build the application as standalone using Pyinstaller but I'm not able to go that far...

I'v followed some tutorials to do so like : https://kitabi.eu/blog/2019-06-26-python-install/ or https://jameskiefer.com/posts/installing-python-3.7-on-debian-8/

But I cant download packages with pip, I got a SSLError("Can't connect to HTTPS URL because the SSL module is not available")

What am I doing wrong ? Do you have some solutions ? Like an existing Docker image of debian jessie with python 3.7 already installed ? lol

Thanks in advance, I'm a bit desesperate at this point o7

🌐
CrownCloud Wiki
wiki.crowncloud.net › How_to_Install_Gitea_on_Debian_11
CrownCloud Wiki - How To Install Python 3 9 On Debian 10=
apt install wget build-essential libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev · By default, Debian 10 comes with Python version 3.7 only.
🌐
RoseHosting
rosehosting.com › home › how to install python 3.10 on debian 11
How to install Python 3.10 on Debian 11 | RoseHosting
June 3, 2022 - First, you will need to log in to your Debian 11 VPS via SSH as the root user: ssh root@IP_ADDRESS -p PORT_NUMBER Next, run the following commands to upgrade all installed packages on your VPS: ... Once all the packages are updated, restart ...
🌐
GitHub
github.com › StackStorm › st2 › issues › 4844
Debian 10 Buster using Python 3.7 · Issue #4844 · StackStorm/st2
January 17, 2020 - It would be useful to support this platform to expand the potential StackStorm user base by having native packaging and installation process for this distribution. The current stable version is Debian 10 Buster which provides Python3.7 only, no Python 3.6 packages are provided by Debian.
Author   StackStorm
Top answer
1 of 3
17

I would say there is no Debian equivalent to Ubuntu's deadsnakes PPA

Under Debian, using Ubuntu packages or repositories is not recommended. As this post appears in search engines, I propose here an answer that is less dangerous for a Debian system.

Installing Python manually is possible. As an example, you can use the following instructions to install 3.5.2 version

Prerequisites

Install dependencies :

sudo apt-get update && sudo apt-get install libssl-dev openssl

Building Python

You can build Python in a specific folder using the --prefix parameter from configure command:

wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
tar zxf Python-3.5.2.tgz
cd Python-3.5.2/
./configure --prefix=/usr/local
make
sudo make install

Instead of /usr/local, one can use another base directory. As an example:

sudo mkdir /opt/python-3.5.2
./configure --prefix=/opt/python-3.5.2

Selecting python version

Using PATH environment variable can help choosing the right python version to use. But one can also use symlinks:

sudo ln -s /opt/python-3.5.2/bin/python3.5 /usr/local/bin/python3
sudo ln -s /opt/python-3.5.2/bin/pip3.5 /usr/local/bin/pip3

Using -f option will allow you to replace existing symlinks


Note: For python 3.9.16 (possibly any +3.9 version) you also might need to install the library: libffi-dev so the dependencies would be:

sudo apt-get update && sudo apt-get install libssl-dev openssl libffi-dev
2 of 3
13

Using the PPA

You can use the PPA on Debian. Pick an Ubuntu version that's from slightly before your Debian version, and it should have all the necessary libraries. For wheezy, the oneiric PPA seems ok (but it lacks more recent Python versions). For jessie, the trusty PPA should work.

To add a PPA on Debian,

  1. Download and add the PPA signing key with:

    gpg --keyserver keyserver.ubuntu.com --recv-keys F23C5A6CF475977595C89F51BA6932366A755776
    gpg --export F23C5A6CF475977595C89F51BA6932366A755776 | sudo tee /usr/share/keyrings/ppa-deadsnakes.gpg > /dev/null
    
  2. Then create a file /etc/apt/sources.list.d/ppa-deadsnakes.list containing:

    deb [signed-by=/usr/share/keyrings/ppa-deadsnakes.gpg] https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu/ trusty main 
    deb-src [signed-by=/usr/share/keyrings/ppa-deadsnakes.gpg] https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu/ trusty main 
    
  3. Finally run apt-get update and install the desired packages.

If you can't get the PPA working for some reasons (maybe you can't find a version that works with the libraries you have), you can download the source and recompile them for your distribution.

Using a chrooted system

What I usually do to test compatibility with other versions is to run older or newer distributions in a chrooted system. For example, you could install various versions of Ubuntu with the Python versions you're interested in, or you could install trusty in a chroot and install the PPA there. For more information, see my schroot guide.

🌐
CrownCloud Wiki
wiki.crowncloud.net
CrownCloud Wiki - How To Install Python 3 10 On Debian 11=
cd Python-3.10.11 ./configure ... and the number 4 represents the number of CPU cores. ... Make install The default Python installation is /usr/bin....
🌐
Linuxize
linuxize.com › home › python › how to install python 3.8 on debian 10
How to Install Python 3.8 on Debian 10 | Linuxize
March 2, 2020 - Debian 10 includes Python version 3.7, which can be installed or updated using the apt tool.