47

How do I install Pip for Python 3.8 ? I made 3.8 my default Python version.

sudo apt install python3.8-pip

gives

unable to locate package python3.8-pip

and running

python3.8 -m pip install [package]

gives

no module named pip

I can't run sudo apt install python3-pip because it installs pip for Python 3.6

6
  • if you installed any standard python distribution then PIP already comes with Python and there is no need to install it. May 10, 2020 at 18:41
  • 1
    The thing is current pip is using 3.6 which I don't want to use since I'm working with Python 3.8
    – Mark
    May 10, 2020 at 18:42
  • 2
    Then you need to use the PIP from Python 3.8. use python -m pip where python is whatever python 3.8 binary May 10, 2020 at 18:44
  • 2
    @juanpa Based on apt, OP's probably using Debian/Ubuntu. Their Python distros don't include pip by default.
    – wjandrea
    May 10, 2020 at 18:46
  • @wjandrea then they definitely shouldn't be using their system python for anything May 10, 2020 at 18:47

5 Answers 5

66

Install pip the official way:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3.8 get-pip.py

made 3.8 my default Python version

It depends on how you did that, but it might break something in your OS. For example some packages on Ubuntu 18.04 might depend on python being python2.7 or python3 being python3.6 with some pip packages preinstalled.

5
  • 1
    You don't need to install PIP for Python 3.8: "pip is already installed if you are using Python 2 >=2.7.9 or Python 3 >=3.4" May 10, 2020 at 18:44
  • 14
    ..."[if] downloaded from python.org or if you are working in a Virtual Environment created by virtualenv or pyvenv."
    – Tomerikoo
    May 10, 2020 at 18:46
  • 4
    Got an error ModuleNotFoundError: No module named 'distutils.cmd'
    – West
    Jun 16, 2022 at 13:19
  • 1
    @West that's a problem of python installation, see askubuntu.com/questions/1239829/…
    – RafalS
    Jun 21, 2022 at 16:30
  • 1
    @Ryabchenko's answer solves the distutils error and should be the accepted answer. stackoverflow.com/a/63281773/3996580 Apr 25 at 16:01
46
sudo apt install python3.8
sudo apt install python3.8-distutils

wget https://bootstrap.pypa.io/get-pip.py
sudo python3.8 get-pip.py
3
  • If I've already got IPython installed via pip3, is manually installing Python 3.8 going to break anything? Aug 11, 2020 at 18:55
  • Thanks that python3.8-distutils saved my time Aug 10, 2022 at 14:11
  • This is the right answer. Apr 25 at 16:00
26

If you installed Python3.8 using apt, the pip documentation advises against using the get-pip.py script:

Be cautious if you are using a Python install that is managed by your operating system or another package manager. get-pip.py does not coordinate with those tools, and may leave your system in an inconsistent state.

The same page suggests running:

python3.8 -m pip --version

to determine if pip is already installed. I installed Python 3.8 on an Ubuntu18 machine using apt install python3.8, and I verified with the command above that it includes pip. It appears that Ubuntu package doesn't install a pip command that you can run directly. But you can run it using the python3.8 binary directly instead, anywhere you would have used pip:

python3.8 -m pip install [package]
2
  • 6
    Your command gives me /usr/bin/python3.8: No module named pip.
    – bomben
    Mar 25, 2022 at 6:20
  • 1
    Thanks for the more specified pip call Aug 10, 2022 at 14:11
1

you can try updating line #1 from /usr/bin/pip3 to #!/usr/bin/python3.8 as below

#!/usr/bin/python3.8
# GENERATED BY DEBIAN

import sys

# Run the main entry point, similarly to how setuptools does it, but because
# we didn't install the actual entry point from setup.py, don't use the
# pkg_resources API.
from pip import main
if __name__ == '__main__':
    sys.exit(main())
1

What I used to install pip according to the current version of default python is:

 sudo apt-get install python-pip

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.