Do you need Ubuntu 20.04? Ubuntu 18.04 comes with Python 3.6, and 3.7 available.
If you do, the deadsnakes PPA has Python 3.5-3.7 for Ubuntu 20.04 (Focal). To add it and install:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get install python3.7
P.s. I'm not a dev and have no experience with Tensorflow so take this with a grain of salt.
(Sidenote: add-apt-repository runs apt-get update automatically, but that's not documented in man add-apt-repository, only add-apt-repository --help. This was fixed in a later release.)
Do you need Ubuntu 20.04? Ubuntu 18.04 comes with Python 3.6, and 3.7 available.
If you do, the deadsnakes PPA has Python 3.5-3.7 for Ubuntu 20.04 (Focal). To add it and install:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get install python3.7
P.s. I'm not a dev and have no experience with Tensorflow so take this with a grain of salt.
(Sidenote: add-apt-repository runs apt-get update automatically, but that's not documented in man add-apt-repository, only add-apt-repository --help. This was fixed in a later release.)
Tensorflow 2.2 now supports python 3.8 so problem is solved now.
For newer Python I prefer the deadsnake ppa. For installing it, try this:
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.7
$ python3.7 -V
Python 3.7.7
The Python 3.7 package from the official Ubuntu 19.10 repositories can be installed in Ubuntu 20.04 without adding any new repositories to your software sources by running the following commands:
sudo apt update
wget -c http://mirrors.kernel.org/ubuntu/pool/main/libf/libffi/libffi6_3.2.1-9_amd64.deb http://security.ubuntu.com/ubuntu/pool/main/p/python3.7/libpython3.7-stdlib_3.7.5-2~19.10ubuntu1_amd64.deb http://security.ubuntu.com/ubuntu/pool/main/p/python3.7/libpython3.7-minimal_3.7.5-2~19.10ubuntu1_amd64.deb http://security.ubuntu.com/ubuntu/pool/main/p/python3.7/python3.7-minimal_3.7.5-2~19.10ubuntu1_amd64.deb http://security.ubuntu.com/ubuntu/pool/main/p/python3.7/python3.7_3.7.5-2~19.10ubuntu1_amd64.deb
sudo apt install ./libffi6_3.2.1-9_amd64.deb ./libpython3.7-minimal_3.7.5-2~19.10ubuntu1_amd64.deb ./libpython3.7-stdlib_3.7.5-2~19.10ubuntu1_amd64.deb ./python3.7-minimal_3.7.5-2~19.10ubuntu1_amd64.deb ./python3.7_3.7.5-2~19.10ubuntu1_amd64.deb
Add Python 3.7 to update-alternatives so that you can switch between Python 3.8 and Python 3.7 by running update-alternatives --config python3.
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7
update-alternatives --config python3
Help with installing python 3.7
I need to use python 3.7 but Ubuntu 20.4 comes with 3.8 pre-installed - can I install it with apt-get alongside 3.8?
Install python 3.11.9 on ubuntu
ubuntu - How to install specific python version? - Unix & Linux Stack Exchange
Videos
I am on a raspberry pi if that makes a difference. I’d like to install python 3.7 ideally so my projects can work. I’ve googled it and sudo apt-get install python3.7 doesn’t work and I see some other meathods but it involves installing other things and I’m not exactly sure what those things are or do
Sorry for the dumb question. Just installed a fresh Ubuntu 20.4 after a couple of years of not touching Linux. I thought I could just sudo apt-get install python3.7 but that doesn't work.
I'd love to be able to use apt-get to minimize the chances I fuck something up, can I do this without having to download and compile it myself?
More specifically:
When I sudo apt-get install python 3.7 I don't get any errors or anything, I just get the following:
$ sudo apt-get install python3.7 [sudo] password for j: Reading package lists... Done Building dependency tree Reading state information... Done Note, selecting 'python3.7-2to3' for regex 'python3.7' Note, selecting 'libpython3.7-stdlib' for regex 'python3.7' 0 upgraded, 0 newly installed, 0 to remove and 9 not upgraded.
Then when I python3.7 I get:
$ python3.7 Command 'python3.7' not found, did you mean: command 'python2.7' from deb python2.7 (2.7.18~rc1-2) command 'python3.8' from deb python3.8 (3.8.2-1ubuntu1.1) Try: sudo apt install <deb name>
And if I look in /usr/bin/:
$ ls /usr/bin/ | grep python python3 python3.8
And:
$ ls -l /usr/bin/python* lrwxrwxrwx 1 root root 9 júl 8 23:57 /usr/bin/python3 -> python3.8 -rwxr-xr-x 1 root root 5457536 apr 27 15:53 /usr/bin/python3.8
It would be wise to use pyenv to safely manage multiple versions of Python installed on the same system.
Nonetheless, this should get you up and running with Python 3.7.10 on Ubuntu 16.04
# WARNING: As of April 30th 2021, Ubuntu Linux 16.04 LTS will no longer supported
# NOTE: It appears that Python 3.7.* has arrived into maintenance mode and will likely
# only be getting security updates. See release notes https://www.python.org/downloads/release/python-3710/
# Install requirements
sudo apt-get install -y build-essential \
checkinstall \
libreadline-gplv2-dev \
libncursesw5-dev \
libssl-dev \
libsqlite3-dev \
tk-dev \
libgdbm-dev \
libc6-dev \
libbz2-dev \
zlib1g-dev \
openssl \
libffi-dev \
python3-dev \
python3-setuptools \
wget
# Prepare to build
mkdir /tmp/Python37
mkdir /tmp/Python37/Python-3.7.10
cd /tmp/Python37/
# Pull down Python 3.7.10, build, and install
wget https://www.python.org/ftp/python/3.7.10/Python-3.7.10.tar.xz
tar xvf Python-3.7.10.tar.xz -C /tmp/Python37
cd /tmp/Python37/Python-3.7.10/
./configure --enable-optimizations
sudo make altinstall
Then you would just call Python like so:
python3.7 ./yourScript.py
This is a screenshot of multiple versions of Python co-existing in a docker container and how they can be distinguished:

Pip should have been installed with this installation as well. To install packages use this format:
pip3.7 -V
I would not recommend manually fiddling around with source code installations and paths. Use pyenv and save yourself the trouble.
All you have to do is:
- Run the
pyenvinstaller - Follow the instructions
- Install the Python versions you need
- Choose which Python version you want to use for a given directory, or globally
For example, to install 3.7, check which versions are available:
pyenv install -l | grep 3.7
Then run:
pyenv install 3.7.1
Now, you can choose your Python version:
pyenv global 3.7.1
This switches your python to point to 3.7.1. If you want the system python, run:
pyenv global system
To check which Python versions are available, run pyenv versions.
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.