I'd like to install the latest Python, which is 3.6 at the time of this post. However, the repository is saying that Python 3.4.2 is the newest version.

I've tried:

$ sudo apt-get update
$ sudo apt-get install python3

python3 is already the newest version.

$ python -V

Python 3.4.2

To upgrade to Python 3.6 on my Windows workstation, I simply downloaded an exe, clicked "next" a few times, and it's done. What's the proper and officially accepted procedure to install Python 3.6 on Debian Jessie?

  • 5
    The default Debian repositories contains software packages specifically compiled for a certain Debian version. Except for security updates (preferably just the fewest changes needed to fix a security hole) new versions of most software may not be available until the next major release to avoid potential instability. – phk Dec 25 '16 at 8:09
  • @phk In that case, wouldn't it be prudent to adopt a behavior similar to pip, i.e. default to 3.4.2 when a version isn't specified, and allow the user to explicitly request 3.6 with a flag? Just an idea :) – dtgq Dec 25 '16 at 10:48
  • 1
    This would mean that the Debian folks would have to maintain all these Python versions for every supported Debian version. Sure, it could be automated but it would be still a lot. Also, the power users who want newer versions could just as well use custom repositories. Sometimes ,the software authors themselves are maintaining them for Debian and other popular Linux distributions, e.g. in the case of Oracle VirtualBox. – phk Dec 25 '16 at 10:58
  • 1
    Python 3.6 (though rc1) just arrived in Debian experimental. It's probably possible to backport it to Jessie, possibly with a little tweaking. – Faheem Mitha Dec 26 '16 at 8:16
  • Update. This finished building successfully for me on Debian stable (jessie). However, that doesn't mean it will install successfully and not cause problems. A reasonable next step would be to test it on a test VM of stable. Does anyone care? – Faheem Mitha Dec 26 '16 at 9:35
up vote 49 down vote accepted

Debian does not have Python 3.6 in its repositories, but testing has it.

$ sudo nano /etc/apt/sources.list
# add
deb http://ftp.de.debian.org/debian testing main
$ echo 'APT::Default-Release "stable";' | sudo tee -a /etc/apt/apt.conf.d/00local
$ sudo apt-get update
$ sudo apt-get -t testing install python3.6
$ python3.6 -V

You asked for:

the proper and officially accepted procedure

but I must point it out that this is not official solution because it uses testing repositories.

  • 32
    Warning: this will upgrade your system to a hybrid of whatever debian release you are running now (probably 'stable') plus 'unstable' plus 'experimental'. This will be far worse than just dist-upgrading to unstable and cherry-picking a few packages from experimental, or (better yet, staying with stable and cherry-picking from backports and/or unstable and/or experimental). Reverting from this will be near impossible. NOT recommended unless you have a LOT of experience with debian and debian packaging – cas Aug 3 '17 at 4:38
  • 5
    edited answer to set apt's default release to stable. and removed the crazy 'apt-get upgrade' (which upgrades everything to the latest versions available in unstable or experimental, except for anything that would cause the removal of another package). That should make this procedure a lot less dangerous but still not safe. And still not recommended for novices. 'experimental' is not for casual use, it's for weird, untested, possibly broken stuff that may conflict or break things even in 'unstable'. It's also used as a staging area for big multi-package upgrades. – cas Aug 3 '17 at 4:54
  • 1
    edited answer as python 3.6.2 is (now) in the testing repository which is safer for the average user. – m4p85r Sep 29 '17 at 4:55
  • 1
    Don't try this - it will take you ages to undo – user3728501 Dec 16 '17 at 17:23
  • 1
    Is this still as risky to do as suggested in August (or Dec) 2017? It's not clear anymore after @cas edited and made his comment. Can someone follow up? – Brian Peterson Jun 11 at 16:52

You can install Python-3.6 on Debian 8 as follows:

wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
tar xvf Python-3.6.3.tgz
cd Python-3.6.3
./configure --enable-optimizations
make -j8
sudo make altinstall
python3.6

It is recommended to use make altinstall according to the official website.

If you want pip to be included, you need to add --with-ensurepip=install to your configure call. For more details see ./configure --help.

Warning: make install can overwrite or masquerade the python binary. make altinstall is therefore recommended instead of make install since it only installs exec_prefix/bin/pythonversion.

Some packages need to be installed to avoid some known problems, see: Common build problems(updated)

Ubuntu/Debian:

sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev liblzma-dev

Alternative of libreadline-dev:

sudo apt install libedit-dev

Fedora/CentOS/RHEL(aws ec2):

sudo yum install zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel \
openssl-devel xz xz-devel libffi-devel

Alternative of openssl-devel:

sudo yum install compat-openssl10-devel --allowerasing

Update

You can download the latest python-x.y.z.tar.gz from here.

To set a default python version and easily switch between them , you need to update your update-alternatives with the multiple python version.

Let's say you have installed the python3.7 on debian stretch , use the command whereis python to locate the binary (*/bin/python). e,g:

/usr/local/bin/python3.7
/usr/bin/python2.7
/usr/bin/python3.5

Add the python versions:

update-alternatives --install /usr/bin/python python /usr/local/bin/python3.7 50
update-alternatives --install /usr/bin/python python /usr/bin/python2.7 40
update-alternatives --install /usr/bin/python python /usr/bin/python3.5 30

The python3.7 with the 50 priority is now your default python , the python -V will print:

Python 3.7.0b2

To switch between them, use:

update-alternatives --config python

Sample output:

There are 3 choices for the alternative python (providing /usr/bin/python).

  Selection    Path                      Priority   Status
------------------------------------------------------------
* 0            /usr/local/bin/python3.7   50        auto mode
  1            /usr/bin/python2.7         40        manual mode
  2            /usr/bin/python3.5         30        manual mode
  3            /usr/local/bin/python3.7   50        manual mode

Press <enter> to keep the current choice[*], or type selection number: 
  • 4
    Don't debian guys recommend checkinstall? Otherwise, it would be wise to install it to /usr/local or /opt. – Ivan Anishchuk Jan 16 '17 at 22:07
  • 3
    According to ./configure --help Python 3.6 installs to /usr/local per default. – Markus Strauss May 4 '17 at 21:03
  • 2
    Having trouble with this answer (e.g., SSL module not available or zlib missing)? See: stackoverflow.com/a/41601137/972128 – kkurian Jun 1 '17 at 16:42
  • 5
    Disclaimer: this takes 20+ hours on a low powered device like the Pi zero. – Antoine Lizée Jul 12 '17 at 7:06
  • 2
    version 3.7 is out – Timo Mar 31 at 15:25

The official recommendation is "you don't actually need newer software"

Don't suffer from Shiny New Stuff Syndrome - DontBreakDebian | Debian Wiki

Most of the advice on that page is geared towards what to do if you want the software to be available system-wide, but I don't think that's necessary in this case.

If you fetch the python sources, build the 3.6 interpreter using --prefix to control where it ends up, and then use virtualenv with the --python option, then you can use python 3.6 without affecting anything outside your project.

The process might go something like this:

$ cd ~
$ mkdir pythonroot
$ mkdir opt
$ mkdir app
$ cd opt
$ wget <python tarball>
$ tar -xvf <python tarball>
$ cd python-3.6
$ ./configure --prefix="$HOME"/pythonroot
$ make
$ make install
$ cd ~
$ cd app
$ virtualenv venv --python ~/pythonroot/bin/python
$ . venv/bin/activate
[venv]$ which python
/home/<user>/pythonroot/bin/python

If you're going to do this, you may want to consider the --enable-optimizations flag in the Python configure script, which seems to enable some features like profile-guided optimization. It increases build times but seems to result in a faster interpreter by 10% or so according to some benchmarks.

  • 3
    This follows general Python rule of "Practicality beats purity". I tend to install pythons from source packages in /opt/python-x.y.z and then run applications from its own virtualenvs. – zgoda Jun 30 '17 at 10:40
  • 1
    Important note: if you're going to do something like this: make sure that whatever user your Python process runs as can't modify the virtualenv – Gregory Nisbet Aug 7 '17 at 16:53
  • 1
    In my opinion this is the best answer. – BringBackCommodore64 Apr 11 at 17:05

You might want to have a look at pyenv : https://github.com/yyuu/pyenv . To quote from the pyenv tutorial at Amaral Lab:

Previously known as Pythonbrew, pyenv lets you change the global Python version, install multiple Python versions, set directory (project)-specific Python versions, and yes create/manage virtual python environments ("virtualenvs"). All this is done on *NIX-style machines (Linux and OS X) without depending on Python itself and it works at the user-level–no need for any sudo commands.

  • 3
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review – Archemar Dec 25 '16 at 10:36
  • You're right, will change the answer. – schaiba Dec 25 '16 at 10:40
  • I think he meant to also include the essential command lines too... – not2qubit Mar 24 '17 at 23:40
  • This works well, except when you're dealing with embedded devices. To "install" a version of python, the source is downloaded and compiled locally. Other than that, pyenv is a great choice and has lots of flexibility, including running different python versions in different directories, and dealing with the very annoying PIP problems. – Brian Bulkowski Apr 16 '17 at 6:29

My preferred way is to use Anaconda or Miniconda to keep the latest version of python and packages installed on Debian.

It's all kept neatly in a folder which makes it very easy to remove later on if you wish. The installer also adds the path to your bashrc (add it yourself if you use another shell).

It comes with pip, and also conda which is another package manager than can be good for more complex pacakges like numpy. Miniconda is a bare bones install, and Anaconda is a full install with many packages, primarily designed for data analysis.

Quickly:

wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh

Read and accept license, if you're not using bash add path: export PATH="/home/$USER/miniconda3/bin:$PATH"

Test:

$ python --version
Python 3.6.0 :: Continuum Analytics, Inc.

Install from PyPi:

# pip install fava

Install from conda:

# conda install numpy

When you want to delete it, remove the folder ~/miniconda3 and the path in your bashrc.

  • After endless problems with installing python from source, this version worked perfect! Note that if you want to work with virtualenv(wrapper) for the enviroment management, you need to add the miniconda library direcotry to LD_LIBRARY_PATH. Eg: add export $LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$HOME/miniconda3/lib" to your .bashrc. – jrast Aug 11 '17 at 23:38
  • "The installer also adds the path to your bashrc" That is the primary reason why I do not use anaconda. Silently masking an existing python environment is not healthy, to say the least. – MisterMiyagi Aug 28 '17 at 6:59

Debian does not have Python 3.6 in it's repositories. Here's a snapshot of the current Python3 status:

wheezy (oldstable) (python): interactive high-level object-oriented language (default python3 version)
    3.2.3-6: all
jessie (stable) (python): interactive high-level object-oriented language (default python3 version)
    3.4.2-2: amd64 arm64 armel armhf i386 mips mipsel powerpc ppc64el s390x
stretch (testing) (python): interactive high-level object-oriented language (default python3 version)
    3.5.1-4: amd64 arm64 armel armhf i386 mips mips64el mipsel ppc64el s390x
sid (unstable) (python): interactive high-level object-oriented language (default python3 version)
    3.5.1-4: alpha amd64 arm64 armel armhf hppa hurd-i386 i386 kfreebsd-amd64 kfreebsd-i386 m68k mips mips64el mipsel powerpc powerpcspe ppc64 ppc64el s390x sh4 sparc64 x32

You can check these out here.

You can install 3.6 either from source, or using something like Linuxbrew for a home directory installation.

With this

sudo echo "http://ftp.fr.debian.org/debian testing main" >> /etc/apt/sources.list

sudo apt-get update
sudo apt-get install -y python3.6

Successfully work.

More : set python3.6 as default

sudo alias python=/usr/bin/python3.6

Right now :

python --version
Python 3.6
  • merci gros !!!! – vdegenne Apr 2 at 13:55
  • Should read sudo echo "deb http://ftp.fr.debian.org/debian testing main" >> /etc/apt/sources.list – declension Sep 28 at 11:28

Python 3.6 (though rc1) just arrived in Debian experimental. I was able to successfully build this on Debian stable (jessie). See the final steps of the build pasted below.

However, that doesn't mean it will install successfully and not cause problems. A reasonable next step would be to test it on a test VM of stable. If anyone cares, I could give it a try - or someone else could try.

A proper release version should arrive in Debian unstable shortly.

dh_builddeb -a
dpkg-deb: building package `python3.6' in `../python3.6_3.6.0~rc1-1_amd64.deb'.
dpkg-deb: building package `python3.6-venv' in `../python3.6-venv_3.6.0~rc1-1_amd64.deb'.
dpkg-deb: building package `libpython3.6-stdlib' in `../libpython3.6-stdlib_3.6.0~rc1-1_amd64.deb'.
dpkg-deb: building package `python3.6-minimal' in `../python3.6-minimal_3.6.0~rc1-1_amd64.deb'.
dpkg-deb: building package `libpython3.6-minimal' in `../libpython3.6-minimal_3.6.0~rc1-1_amd64.deb'.
dpkg-deb: building package `libpython3.6' in `../libpython3.6_3.6.0~rc1-1_amd64.deb'.
dpkg-deb: building package `python3.6-dev' in `../python3.6-dev_3.6.0~rc1-1_amd64.deb'.
dpkg-deb: building package `libpython3.6-dev' in `../libpython3.6-dev_3.6.0~rc1-1_amd64.deb'.
dpkg-deb: building package `python3.6-dbg' in `../python3.6-dbg_3.6.0~rc1-1_amd64.deb'.
dpkg-deb: building package `libpython3.6-dbg' in `../libpython3.6-dbg_3.6.0~rc1-1_amd64.deb'.
 dpkg-genchanges  >../python3.6_3.6.0~rc1-1_amd64.changes
dpkg-genchanges: including full source code in upload
 dpkg-source --after-build python3.6-3.6.0~rc1
dpkg-buildpackage: full upload (original source is included)
Now running lintian...
W: python3.6 source: newer-standards-version 3.9.8 (current is 3.9.6)
N: 56 tags overridden (26 errors, 27 warnings, 3 info)
Finished running lintian.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.