2

I'm trying to use pip to install some packages that I need, but I came across a problem. My default version of python is python3.10 but when I try using pip to install packages for it, it installes them for python3.8

This is the output of pip --version:

pip 22.1.2 from /usr/local/lib/python3.8/dist-packages/pip (python 3.8)

Is there a way to change this so that I can install packages for python 3.10?

When I try to run python3 -m pip --version I get:

/usr/local/bin/python3: No module named pip
WholesomeGhost
  • 1,101
  • 2
  • 17
  • 31
  • 1
    How can you call python from the command line? If it's `python3` then you're best off using `python3 -m pip --version` – Steve Jun 15 '22 at 08:15
  • See [Dealing with multiple Python versions and PIP?](https://stackoverflow.com/questions/2812520/dealing-with-multiple-python-versions-and-pip) – Steve Jun 15 '22 at 08:19
  • I've edited my response with the output of your suggestion. – WholesomeGhost Jun 15 '22 at 08:19
  • Do you use python from the command line? How do you typically call the 3.10 version? – Steve Jun 15 '22 at 08:21
  • with just `python3`, this calls the 3.10 version – WholesomeGhost Jun 15 '22 at 08:23
  • You'll want to install pip (solutions for Mac and Ubuntu in answers to [ImportError: No module named pip](https://stackoverflow.com/questions/18363022/importerror-no-module-named-pip)), then probably still want to use `python3 -m pip` commands. – Steve Jun 15 '22 at 08:28
  • I've also just seen [this answer](https://stackoverflow.com/a/61562956/5358968) which suggests `python -m ensurepip` which might help. – Steve Jun 15 '22 at 08:32
  • @Steve `ensurepip` will not work with python version less than 3.4 as it was introduced with version 3.4 – Prashant Maurya Jun 15 '22 at 10:02
  • @PrashantMaurya so it should work fine with python 3.10 then – Steve Jun 15 '22 at 22:52
  • @Steve `ensurepip` shouldn't work with python 3.10 as it was introduced in the later versions – Prashant Maurya Jun 16 '22 at 05:45
  • 1
    @PrashantMaurya `python3.10` means major version 3, minor version 10 - 3.10 is currently the latest stable release (released 2021) and more recent than 3.4 (released 2014, no longer maintained). – Steve Jun 16 '22 at 07:02
  • @Steve you are right, my fault – Prashant Maurya Jun 16 '22 at 08:52

2 Answers2

0

Download get-pip.py file from any of the following options:

  • Download it manually from here.
  • Download it from terminal/cmd using: wget https://bootstrap.pypa.io/get-pip.py
  • Download it from terminal/cmd using: curl https://bootstrap.pypa.io/get-pip.py

Then run the command python3 get-pip.py, it will install pip in the python version invoked by python3(which is 3.10 as you have stated). Install packages using command python3 -m pip install package_name

Prashant Maurya
  • 639
  • 4
  • 13
0

Since you've said you can call the desired python version with the command python3, it's best to call pip via

python3 -m pip

This ensures you're installing packages to the correct version (Dealing with multiple Python versions and PIP?).

To install pip if it's missing, you can use ensurepip (as per this answer)

python3 -m ensurepip

It's probably worth mentioning venv which lets you create a local python environment to keep your packages separate for different projects.

Steve
  • 1,579
  • 10
  • 23