Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install pip for Python 3.9 on Ubuntu 20.04

Ubuntu 20.04 comes with Python 3.8. I cannot uninstall Python 3.8 but I need Python 3.9

I went ahead and installed Python 3.9 from:

sudo add-apt-repository ppa:deadsnakes/ppa

sudo apt install python3.9

How do I install pip for python 3.9?

Installing pip using sudo apt-get install python3-pip does not work for me as it installs pip for python 3.8

Installing pip using python3.9 get-pip.py gives an error:

~/python_tools$ python3.9 get-pip.py  Traceback (most recent call last):   File "/home/ubuntu/python_tools/get-pip.py", line 23704, in <module>     main()   File "/home/ubuntu/python_tools/get-pip.py", line 198, in main     bootstrap(tmpdir=tmpdir)   File "/home/ubuntu/python_tools/get-pip.py", line 82, in bootstrap     from pip._internal.cli.main import main as pip_entry_point   File "<frozen zipimport>", line 259, in load_module   File "/tmp/tmpkwyc8h7j/pip.zip/pip/_internal/cli/main.py", line 10, in <module>   File "<frozen zipimport>", line 259, in load_module   File "/tmp/tmpkwyc8h7j/pip.zip/pip/_internal/cli/autocompletion.py", line 9, in <module>   File "<frozen zipimport>", line 259, in load_module   File "/tmp/tmpkwyc8h7j/pip.zip/pip/_internal/cli/main_parser.py", line 7, in <module>   File "<frozen zipimport>", line 259, in load_module   File "/tmp/tmpkwyc8h7j/pip.zip/pip/_internal/cli/cmdoptions.py", line 18, in <module> ModuleNotFoundError: No module named 'distutils.util' 
like image 674
Gilson Avatar asked Jan 09 '21 16:01

Gilson


People also ask

Does Python 3.9 support pip?

The current version of pip works on: Windows, Linux and MacOS. CPython 3.7, 3.8, 3.9, 3.10 and latest PyPy3.


1 Answers

You can install pip for python 3.9 the following way:

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 

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.

These instructions are based in part on the official installation instructions provided by the pip maintainers.

like image 73
Shane Bishop Avatar answered Sep 21 '22 19:09

Shane Bishop