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.

Instead, to run python3.5, run the command python3.5 (or python3.X for any other version of python).


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.

Answer from Nephente on askubuntu.com
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-to-install-a-specific-python-version-in-linux
How to install a specific Python version in Linux
Note: Depending on our Linux distribution, the version of Python that is installed by default may vary.
๐ŸŒ
Reddit
reddit.com โ€บ r/python โ€บ installing specific python version in ubuntu 20
r/Python on Reddit: Installing specific python version in Ubuntu 20
June 21, 2020 -

Beginners beware, this post isn't about overwriting the default python installation, but working with alternative installation of other versions of python on your Ubuntu 20. If you overwrite your default python you are likely to encounter several other issues that may cause you to reinstall your OS, so please go through the complete post and try to make alternate installation.

In this post, I am going to write about a way to install specific python version (python 3.7.5) in your Ubuntu 20 system which initially has Python 3.8. Since, the project I have done till now had the Python version of 3.6 and 3.7. But, after I updated my OS to Ubuntu 20, my virtual environment could not be set upped as per the project requirements.

Because I wanted my old projects to be compatible, first, I thought of way to override my python 3.8 with python 3.7 but had so many other issues.

Now, I have found a way to deal with this version issue, which I will be explaining below.

1 Checking, Initial version of Python that comes with Ubuntu 20

$ python3 --version
Python 3.8.2

2 Installation of pip

a. First updating the packages

$ sudo apt update

b. Installation of pip

# The command below will install all the dependencies required for building Python modules.
$ sudo apt install python3-pip

c. Verification of pip installed

$ pip3 --version
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)

3 Install virtualenv in your local system

Virtualenv is where all the packages required for project will be kept without dealing with local system packages.

$ pip3 install virtualenv

If you want to use Python 3.8 in your project, then, below process can be followed.

# my_project is the project directory
$ mkdir my_project && cd my_project

# Create a virtual environment in your project directory
$ python3 -m virtualenv .venv

# Activating the environment
$ source .venv/bin/activate
$ python --version
Python 3.8.2

But, this isn't our objective, we want to use other python version (Lets say Python 3.7.5). So, for that please see the below steps.

First install specific version of python in your local system without causing conflict in local system

# Update and Upgrades of packages
$ sudo apt update  
$ sudo apt upgrade -y

# Next, install the build tools and Python 3.7 dependencies using the following command:
$ sudo apt install build-essential libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev tk-dev libffi-dev

# Next, download the source code of Python 3.7 using the wget tool:
$ cd /tmp
$ wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tar.xz

# Next, decompress the tar file using:
$ tar xf Python-3.7.5.tar.xz

# Next, navigate inside your decompressed Python-3.7.0 folder:
$ cd Python-3.7.5

# Build Python 3.7.5 code using the configure and make tools:
$ ./configure --enable-optimizations
$ sudo make -j 8

# Next, run the following command to install the Python 3.7.5:
# Prefer "altinstall" than "install" because install will override the current OS python, and will cause other conflicts in OS.
$ sudo make altinstall


# Python 3.7.5 can run using:
$ python3.7 

After the specific version of python is installed successfully.

Create virtual environment in your project with specific version installed

# First know your specific python version installed path
$ which python3.7
/usr/local/bin/python3.7

# my_project is a project directory
$ mkdir my_project && cd my_project

# Create virtualenv with the specific python version path
$ python3 -m virtualenv --python=/usr/local/bin/python3.7 .venv

# Activating the virtualenv 
$ source .venv/bin/activate

# Test the python path and version
$ which python
my_project/.venv/bin/python

# python --version
Python 3.7.5

Now can work on any project as required.

Would like to get recommendation on this process, or any other ways it can be dealt with.

๐ŸŒ
Ruan Bekker's Blog
ruan.dev โ€บ blog โ€บ 2022 โ€บ 06 โ€บ 23 โ€บ install-a-specific-python-version-on-ubuntu
Install a specific Python version on Ubuntu | Ruan Bekker's Blog
June 23, 2022 - Once it completes, you can symlink the python binary so that it's detected by your PATH, if you have no installed python versions or want to use it as the default, you can force overwriting the symlink: $ sudo ln -fs /usr/local/bin/python3 /usr/bin/python3
๐ŸŒ
Reddit
reddit.com โ€บ r/almalinux โ€บ install specific version of python
r/AlmaLinux on Reddit: Install specific version of Python
November 13, 2024 -

I am not so familiar with working with server but now i got an almalinux8

  Virtualization: kvm
  Operating System: AlmaLinux 8.10 (Cerulean Leopard)
  CPE OS Name: cpe:/o:almalinux:almalinux:8::baseos
  Kernel: Linux 4.18.0-553.16.1.el8_10.x86_64
  Architecture: x86-64

Next, I need to install python3.9 without changing the default version used by the whole system

python3 --version
Python 3.6.8

and I see

sudo dnf module list | grep -i python
[sudo] password for xxxx:
libselinux-python    2.8             common                                   Python 2 bindings for libselinux
python27             2.7 [d]         common [d]                               Python programming language, version 2.7
python36             3.6 [d][e]      build, common [d]                        Python programming language, version 3.6
python38             3.8 [d]         build, common [d]                        Python programming language, version 3.8
python39             3.9 [d]         build, common [d]                        Python programming language, version 3.9
python38-devel       3.8             build, common                            Python programming language, version 3.8
python39-devel       3.9             build, common                            Python programming language, version 3.9

So my idea is enable, install and modify only my bash

sudo dnf module enable python39
sudo dnf install python39
#open ~/.bashrc
# Add Python 3.9 to PATH
export PATH="/usr/bin/python3.9:$PATH"
alias python=python3.9

Is this the correct way to go? Am I missing something? Thanks and I am sorry for this basic question but I just start my journey to work with server.

๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ questions โ€บ how-to-install-a-specific-python-version-on-ubuntu
How to install a specific Python version on Ubuntu? | DigitalOcean
March 1, 2021 - This is going to be beyond the scope of the tutorial. However here is how you could install a specific version if needed: ... Finally you can create a symlink for that specific Python version so that you could use the binary from anywhere:
Find elsewhere
๐ŸŒ
Quora
quora.com โ€บ How-can-one-install-a-specific-version-of-Python-in-Ubuntu
How can one install a specific version of Python in Ubuntu? - Quora
Answer (1 of 5): Yes we can install any specific version of Python. First install dependencies: [code]sudo apt-get install build-essential checkinstall sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev [/code]Then downl...
๐ŸŒ
Quora
quora.com โ€บ How-do-you-install-a-different-Python-version-in-Linux
How to install a different Python version in Linux - Quora
Answer (1 of 2): As Iโ€™ve said a number of times: you need to be careful that you do not alter any of the soft links to Python versions in /usr/bin. Doing so can cause misbehavior that can be very hard to track and fix. If I were you, Iโ€™d record all the soft links before the install and ...
๐ŸŒ
Real Python
realpython.com โ€บ intro-to-pyenv
Managing Multiple Python Versions With pyenv โ€“ Real Python
September 1, 2025 - Note: When using local, you donโ€™t need to specify a full version number: ... $ pyenv local 3.13 $ python --version Python 3.13.5 $ pyenv local 3.13.4 $ python --version Python 3.13.4 $ pyenv local 3.6 pyenv: version '3.6' not installed
Top answer
1 of 3
11

Python has got its own package managing facilities, in parallel to the one sets by the Linux distributions (including Ubuntu). The repository is the Pypi - Python Package Index, and packages are installed with pip or the easy_install script, which is part of Python's setuptools package.

As a rule of thumb, you should not use both the packages installed via pip/setuptools, and packages available to your distro (via apt-get, yum, urpmi, etc...) as they might conflict.

So, one of the less error prone way to deal with it is to have separate Python installs in your system - leave the python that came with the system for system scripts and such - on this python, make use of packages installed by your package manager only. And install other versions of Python (or even the same), to be run with "virtualenv"s - on these other install you install things with pip/setuptools only.

(And even if one opt to live boldly and not use virtualenvs, installing another python version on the same prefix (/usr, and even /usr/local) than your system's Python is a source to confusing errors and conflicts).

Note that the Debian - and Ubuntu - systems devised a way to run parallel official Python's in /usr, and to have apt-get to install Python packages to both Python versions at once. This mostly works, but they mess with Python's default directory hierarchy, and some applications fail to use Python in this way. (It is also a mess to find the module files themselves in a Debian or Ubuntu). So the above method apply as a recommendation even if your system do have more than one version of Python available on apt-get.

In short, once you have compiled your desired version of Python, do this:

  1. use your system's package manager to install "python-setuptools" and "python-virtualenv" (not sure if these are the actual package names).
  2. Use virtualenv to create an environment from which you will use your different Python version
  3. Activate your virtualenv, and install Python packages using pip on it.

Virtualenv does feature a "--help" switch to help you, but you basically do:

Copy$ virtualenv -p <path-to-python-interpreter>  <environment-dir>
$ source <environment-dir>/bin/activate

And there you are - all things using Python will "see" the interpreter in the virtualenv, due to environment variables set.

2 of 3
6

ubuntu 10.04 doesn't have a python2.7 package. You have to build 2.7 yourself. I did read an article about ubuntu releasing a python2.7 package when 12.04 came out but i'm not sure what the repository location is.

http://eli.thegreenplace.net/2011/10/10/installing-python-2-7-on-ubuntu/

or:

Copysudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python2.7

https://askubuntu.com/questions/101591/install-python-2-7-2-on-ubuntu-10-04-64-bit

this question has lots of answers online.

๐ŸŒ
Clouding.io
help.clouding.io โ€บ hc โ€บ en-us โ€บ articles โ€บ 13555555842588-How-to-install-different-versions-of-Python-on-Ubuntu
How to install different versions of Python on Ubuntu โ€“ Clouding.io
May 1, 2024 - This command will install the latest stable version of Python 3 available in the Ubuntu repositories: ... If you need to install specific versions of Python or work with multiple versions of Python on your system, a popular option is to use pyenv.
๐ŸŒ
RoseHosting
rosehosting.com โ€บ home โ€บ how to install and switch python versions on ubuntu 20.04
How to Install and Switch Python Versions on Ubuntu 20.04 | RoseHosting
October 5, 2022 - To install Python3.7, you need to add the repository first: sudo apt install software-properties-common sudo add-apt-repository ppa:deadsnakes/ppa sudo apt update ยท Once, the repo is added and the system is updated, execute the command below: ...
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Install python 3.11.9 on ubuntu - Python Help - Discussions on Python.org
In the VM, I have run the following: sudo apt install sudo apt upgrade this: python3 --version returns: Python 3.10.12 When I run: sudo apt install python3 I receive this message: python3 is already at the newest version (3.10.6-1~22.04) When...
Published ย  April 16, 2024
๐ŸŒ
Medium
medium.com โ€บ analytics-vidhya โ€บ how-to-install-and-switch-between-different-python-versions-in-ubuntu-16-04-dc1726796b9b
How to install and switch between different python versions in ubuntu 16.04. | by Md Mahbubur Rahman | Analytics Vidhya | Medium
February 8, 2024 - We will set the priority by the following commands: sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2sudo update-alternatives --install ...
๐ŸŒ
Built In
builtin.com โ€บ articles โ€บ pip-install-specific-version
Pip Install a Specific Version: A Guide | Built In
Uninstall and Install Method: First, run pip uninstall <package_name>, then execute pip install <package_name>==<version>. Overwrite Method: Install the specific Python package and add --ignore installed to overwrite the previous version.