How to install pip for Python 3.9 on Ubuntu 20.04
You can install pip
for python 3.9 the following way:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.pypython3.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
and then rerun your get-pip.py
command. If you are not on a Debian-based distribution, use the equivalent command for your distribution's package manager.
Pip is included by default in python 3.4 and later.
python3.9 -m pip --version
If, for some reason, pip is not installed, you can install it manually by using get-pip:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.pypython3.9 get-pip.py
An alternative that relies only on deadsnakes/ppa
is to install python3.9-venv
.
sudo apt-get install python3.9-venvpython3.9 -m venv venvsource venv/bin/activatepip --version# pip 21.1.3 from /home/.../venv/lib/python3.9/site-packages/pip (python 3.9)
Perhaps easier to keep coherent over time, but forcing into Virtualenv.
This method was born out a problem on Ubuntu 18. Other proposals in the thread aimed at OP's target (20.04) did not work. The install script from PyPa ends on Ubuntu 18 with:
python3.9 get-pip.py# ...# AttributeError: 'HTMLParser' object has no attribute 'unescape'