Ubuntu – How to install a different Python version using apt-get

aptpythonsoftware installation

How can I install a different version of Python using apt-get?

Obviously I realise I can install using the source tar ball, however I would prefer not to install from source and instead use the package manager, as that's what it's there for. Surely somewhere reputable builds .deb files for the latest Python releases (why python.org don't is beyond me) that I can reference.

What do I need to do to reference them and what issues might it create when upgrading to the next version?

If there is no way except for building from source, is there a (pseudo) package that I can can install that will provide all of the dependencies needed without having to find and install each individually? So that I don't get:

The necessary bits to build these optional modules were not found:
_bz2                  _curses               _curses_panel      
_dbm                  _gdbm                 _lzma              
_sqlite3              _ssl                  _tkinter           
readline              zlib  

Best Answer

Felix Krull runs a PPA offering basically any version of Python (seriously, there is 2.3.7 build for vivid...) for many Ubuntu releases at https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa.

Do the usual:

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.5

It will not overwrite your existing python3.4 which is still symlinked as python3.

DON'T change the symlink! There are apparently many system functions that don't work properly with python3.5.

I tried this and afterwards couldn't open a terminal, software updater,...

cd /usr/bin
sudo rm python3

The upgrade to Wily will adapt the meta-package python3 to point to python3.5. I don't expect any breakage, but at this point the foreign repository is not needed anymore. So to be really safe, you can purge the PPA before doing the upgrade.