简体   繁体   中英

Can pip (python2) and pip3 (python3) coexist?

I always thought that pip was for Python 2 and pip3 was for Python 3. To install the different versions of pip I have done the following:

sudo apt-get install python-pip
sudo apt-get install python3-pip

then I get the following as one would expect:

$ pip --version
pip 8.1.1 from /usr/lib/python2.7/dist-packages (python 2.7)
$ pip3 --version
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)

Those are old versions, though, so I do the following:

$ sudo pip install pip --upgrade

and I get this:

$ pip --version
pip 19.0.3 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)
$ pip3 --version
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)

and when I do a pip3 install for some package, I get the following message:

You are using pip version 8.1.1, however version 19.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

Well, I already ran that, so I try this:

$ sudo pip3 install pip --upgrade
Installing collected packages: pip
  Found existing installation: pip 8.1.1
    Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr
Successfully installed pip-19.0.3

But now I get this:

$ pip --version
pip 19.0.3 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)
$ pip3 --version
pip 19.0.3 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)

Is that correct? Does this matter? Does a pip version from Python 3.5 work for installing Python 2 packages?

UPDATE

Based on the answer provided by @furas, these are all the commands I run to get updated versions of pip and pip3 installed correctly:

sudo apt-get install python-pip --yes
sudo apt-get install python3-pip --yes
sudo python3 -m pip install pip --upgrade
sudo python -m pip install pip --upgrade --force # this line fixes the pip install to point to the python2 version instead of the python3 version

and that yields the following:

$ pip --version
pip 19.0.3 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)
$ pip3 --version
pip 19.0.3 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)

Every Python should have own pip because every Python may use differen version of the same module and every Python installs modules in different folder.

You can use Python2 to install pip for Python2 and it should create correct file pip

python -m pip install -U --force pip

You should also have pip , pip2 , pip2.7 , pip3 , pip3.5 . You can even have pip3.6 , pip3.7 at the same time.

Write in console pip and press tab and it should shows you all programs which starts with pip

You can find full path for pip with

which pip 

and see it is python's script.

Different pip has different first line #!/usr/bin/python or #!/usr/bin/python3.5 . Rest code should be the same for all versions.

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