简体   繁体   中英

pip installing python packages for the wrong version

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM