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 https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3.9 get-pip.py

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 get-pip.py --user

If you get an error like No module named 'distutils.util' when you run python3.9 get-pip.py, 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 (setup.py) ... error
error: subprocess-exited-with-error

× python setup.py 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/__init__.py", line 14, in <module>
from setuptools.dist import Distribution, Feature
File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 24, in <module>
from setuptools.depends import Require
File "/usr/lib/python3/dist-packages/setuptools/depends.py", line 7, in <module>
from .py33compat import Bytecode
File "/usr/lib/python3/dist-packages/setuptools/py33compat.py", 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

自由撰稿人,时评人,平等公义追求者