简体   繁体   English

pip(python2)和pip3(python3)可以共存吗?

[英]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: 我一直认为pip适用于Python 2,而pip3适用于Python 3.要安装不同版本的pip,我已完成以下操作:

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: 当我为某个软件包安装pip3时,我收到以下消息:

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? Python 3.5的pip版本是否适用于安装Python 2软件包?

UPDATE 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: 基于@furas提供的答案,这些是我为了正确安装pip和pip3的更新版本而运行的所有命令:

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. 每个Python都应该拥有自己的pip因为每个Python都可以使用相同模块的不同版本,每个Python都会在不同的文件夹中安装模块。

You can use Python2 to install pip for Python2 and it should create correct file pip 您可以使用Python2Python2安装pip ,它应该创建正确的文件pip

python -m pip install -U --force pip

You should also have pip , pip2 , pip2.7 , pip3 , pip3.5 . 你还应该有pippip2pip2.7pip3pip3.5 You can even have pip3.6 , pip3.7 at the same time. 你甚至可以同时拥有pip3.6pip3.7

Write in console pip and press tab and it should shows you all programs which starts with pip 写入控制台pip并按下选项卡,它应显示所有以pip开头的程序

You can find full path for pip with 你可以找到pip完整路径

which pip 

and see it is python's script. 并看到它是python的脚本。

Different pip has different first line #!/usr/bin/python or #!/usr/bin/python3.5 . 不同的pip有不同的第一行#!/usr/bin/python#!/usr/bin/python3.5 Rest code should be the same for all versions. 所有版本的Rest代码应该相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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