I have a ubuntu20, the version of the python3 interpreter that comes with it is 3.8, but I installed a python3.9 through sudo pip install python3.9 and then I want to install a pip package manager for python3.9, if through sudo apt install python3-pip command to install pip, it is installed for python3.8 by default.

To verify the authenticity of what I said, you can type pip -V in the terminal

 pip -V                    
pip 21.2.4 from /home/bot/.local/lib/python3.8/site-packages/pip (python 3.8)

So, at this time, first uninstall the pip installed through the apt package manager

 sudo apt purge python3-pip
Why use apt to uninstall pip? Because my previous pip was installed through apt, the Python that comes with Linux does not include pip, and pip is generally installed through a method similar to apt install python3-pip. But this is not the only way! The following is to install pip through the get-pip.py script, which is more flexible and can adapt to multiple versions

step one:

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

 ➜  ~ cd Downloads 
➜  Downloads curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1911k  100 1911k    0     0  1864k      0  0:00:01  0:00:01 --:--:-- 1864k

Step 2:

Run python3.9 get-pip.py command

 ➜  Downloads python3.9 get-pip.py 
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting pip
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/ca/31/b88ef447d595963c01060998cb329251648acf4a067721b0452c45527eb8/pip-21.2.4-py3-none-any.whl (1.6 MB)
Installing collected packages: pip
Successfully installed pip-21.2.4
Note that for which interpreter you want to install pip, run this script with that interpreter. It's better to use absolute path, lest you make a mistake

Step 3:

Run pip -V command

 ➜  Downloads pip -V
pip 21.2.4 from /home/bot/.local/lib/python3.9/site-packages/pip (python 3.9)

You're done!

Reference tutorial
Multi-version Python installation pip and pip version management ultimate tutorial

pypy install pip

The above method can be used to solve the pip management under the multiple versions of Python that comes with Linux.

But if you have some self-compiled interpreters, such as Python3.10 or pypy, you can also execute get-pip.py scripts.

The difference is that such a pip path is not the path of apt, but the path where the interpreter is located.

For example, if I execute the command ./python3.9 ~/Downloads/get-pip.py /home/bot/opt/python/pypy/pypy3.9/bin ---ce0b7a81a865d7ce71b547af69a54d5c---, then pip appears in /home/bot/opt/python/pypy/pypy3.9/bin , not other


universe_king
3.4k 声望680 粉丝