install python3.9 on ubuntu 18.04 20.04

More Less
2 min readFeb 6, 2023

Installing Python 3.9 on Ubuntu with apt is a relatively straightforward process and will only take a few minutes:

  1. Start by updating the packages list and installing the prerequisites:
sudo apt update
sudo apt install software-properties-common

2. Next, add the deadsnakes PPA to your sources list:

sudo add-apt-repository ppa:deadsnakes/ppa

When prompted press Enter to continue:

Press [ENTER] to continue or Ctrl-c to cancel adding it.
  • Press [ENTER] to continue or Ctrl-c to cancel adding it.Copy

3. Once the repository is enabled, install Python 3.9 with:

sudo apt install python3.9

4. At this point, Python 3.9 is installed on your Ubuntu system and ready to be used. You can verify it by typing:

python3.9 --versionCopy
Python 3.9.16

Then pip can be installed.

curl -o

It is important you use python3.9 instead of just python3, to ensure pip is installed for python 3.9.

If you see any permissions errors, you may need to use

python3.9 --user

If you get an error like No module named 'distutils.util' when you run python3.9, and you are on a Debian-based Linux distribution, run

sudo apt install python3.9-distutils

when doing pip install, met this error:

  Preparing metadata ( ... error
error: subprocess-exited-with-error

× python egg_info did not run successfully.
│ exit code: 1
╰─> [12 lines of output]
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 14, in <module>
File "/usr/lib/python3/dist-packages/setuptools/", line 14, in <module>
from setuptools.dist import Distribution, Feature
File "/usr/lib/python3/dist-packages/setuptools/", line 24, in <module>
from setuptools.depends import Require
File "/usr/lib/python3/dist-packages/setuptools/", line 7, in <module>
from .py33compat import Bytecode
File "/usr/lib/python3/dist-packages/setuptools/", line 54, in <module>
unescape = getattr(html, 'unescape', html_parser.HTMLParser().unescape)
AttributeError: 'HTMLParser' object has no attribute 'unescape'
[end of output]

solution is:

pip3 install --upgrade setuptools



More Less