pip 或 pip3 为 Python 3 安装软件包?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40832533/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
pip or pip3 to install packages for Python 3?
提问by Ammar Alyousfi
I have a Macbook with OS X El Captain. I think that Python 2.7
comes preinstalled on it. However, I installed Python 3.5
too. When I started using Python 3
, I read that if I want to install a package, I should type:
我有一台装有 OS X El Captain 的 Macbook。我认为这Python 2.7
是预先安装的。不过我也安装Python 3.5
了。当我开始使用时Python 3
,我读到如果我想安装一个包,我应该输入:
pip3 install some_package
Anyway, now when I use
无论如何,现在当我使用
pip install some_package
I get some_package
installed for Python 3
. I mean I can import it and use it without problems. Moreover, when I type just pip3
in Terminal
, I got this message about the usage:
我some_package
安装了Python 3
. 我的意思是我可以导入它并毫无问题地使用它。此外,当我输入pip3
时Terminal
,我收到了有关用法的消息:
Usage:
pip <command> [options]
which is the same message I get when I type just pip
.
这与我在键入时收到的消息相同pip
。
Does it mean that in previos versions, things were different, and now pip
and pip3
can be used interchangeably? If so, and for the sake of argument, how can I install packages for Python 2
instead of Python 3
?
这是否意味着在previos版本,事情是不同的,现在pip
和pip3
可以互换使用?如果是这样,并且为了争论,我如何安装包Python 2
而不是Python 3
?
采纳答案by CSJ
Your pip
is a soft link to the same executable file path with pip3
.
you can use the commands below to check where your pip
and pip3
real paths are:
您pip
是指向同一可执行文件路径的软链接pip3
。您可以使用以下命令来检查您的路径pip
和pip3
真实路径在哪里:
$ ls -l `which pip`
$ ls -l `which pip3`
You may also use the commands below to know more details:
您也可以使用以下命令了解更多详情:
$ pip show pip
$ pip3 show pip
When we install different versions of python, we may create such soft links to
当我们安装不同版本的python时,我们可能会创建这样的软链接
- set default pip to some version.
- make different links for different versions.
- 将默认 pip 设置为某个版本。
- 为不同的版本制作不同的链接。
It is the same situation with python
, python2
, python3
情况与python
, python2
,相同python3
More information below if you're interested in how it happens in different cases:
如果您对它在不同情况下的发生方式感兴趣,请查看以下更多信息:
回答by apadana
If you had python 2.x and then installed python3, your pip will be pointing to pip3.
you can verify that by typing pip --version
which would be the same as pip3 --version
.
如果你有 python 2.x 然后安装了 python3,你的 pip 将指向 pip3。您可以通过键入pip --version
与pip3 --version
.
On your system you have now pip, pip2 and pip3.
在您的系统上,您现在拥有pip、pip2 和 pip3。
If you want you can change pip to point to pip2 instead of pip3.
如果需要,您可以将 pip 更改为指向 pip2 而不是 pip3。
回答by Ani Menon
When you install python3
, pip3
gets installed. And if you don't have another python installation(like python2.7) then a link is created which points pip
to pip3
.
当您安装时python3
,pip3
就会安装。如果你没有其他的Python安装(如python2.7),然后链接创建这点pip
来pip3
。
So pip
is a link to to pip3
if there is no other version of python installed(other than python3).
pip
generally points to the first installation.
所以pip
是一个链接pip3
,如果有Python安装的任何其他版本(比python3等)。
pip
一般指向第一次安装。
回答by Max Uppenkamp
This is a tricky subject. In the end, if you invoke pip
it will invoke either pip2
or pip3
, depending on how you set your system up.
这是一个棘手的话题。最后,如果您调用pip
它,它将调用pip2
或pip3
,这取决于您如何设置系统。
回答by Victoria Stuart
By illustration:
举例说明:
pip --version
pip 19.0.3 from /usr/lib/python3.7/site-packages/pip (python 3.7)
pip3 --version
pip 19.0.3 from /usr/lib/python3.7/site-packages/pip (python 3.7)
python --version
Python 3.7.3
which python
/usr/bin/python
ls -l '/usr/bin/python'
lrwxrwxrwx 1 root root 7 Mar 26 14:43 /usr/bin/python -> python3
which python3
/usr/bin/python3
ls -l /usr/bin/python3
lrwxrwxrwx 1 root root 9 Mar 26 14:43 /usr/bin/python3 -> python3.7
ls -l /usr/bin/python3.7
-rwxr-xr-x 2 root root 14120 Mar 26 14:43 /usr/bin/python3.7
Thus, my in my default system python (Python 3.7.3), pip
ispip3
.
因此,我在我的默认系统 python (Python 3.7.3) 中pip
是pip3
.
回答by Mohammad Reza
I think pip
, pip2
and pip3
are not soft links to the same executable file path. Note this commands and results in my linux terminal:
我认为pip
,pip2
并且pip3
不是指向同一可执行文件路径的软链接。在我的 linux 终端中注意这个命令和结果:
mrz@mrz-pc ~ $ ls -l `which pip`
-rwxr-xr-x 1 root root 292 Nov 10 2016 /usr/bin/pip
mrz@mrz-pc ~ $ ls -l `which pip2`
-rwxr-xr-x 1 root root 283 Nov 10 2016 /usr/bin/pip2
mrz@mrz-pc ~ $ ls -l `which pip3`
-rwxr-xr-x 1 root root 293 Nov 10 2016 /usr/bin/pip3
mrz@mrz-pc ~ $ pip -V
pip 9.0.1 from /home/mrz/.local/lib/python2.7/site-packages (python 2.7)
mrz@mrz-pc ~ $ pip2 -V
pip 8.1.1 from /usr/lib/python2.7/dist-packages (python 2.7)
mrz@mrz-pc ~ $ pip3 -V
pip 9.0.1 from /home/mrz/.local/lib/python3.5/site-packages (python 3.5)
As you see they are exist in different paths.
如您所见,它们存在于不同的路径中。
pip3 always operates on the Python3 environment only, as pip2 does with Python2. pip operates on whichever environment is appropriate to the context. For example if you are in a Python3 venv, pip will operate on the Python3 environment.
pip3 始终仅在 Python3 环境中运行,就像 pip2 对 Python2 所做的那样。pip 在适合上下文的任何环境上运行。例如,如果您在 Python3 venv 中,pip 将在 Python3 环境中运行。
回答by mikeqfu
If you installed Python 2.7, I think you could use pip2
and pip2.7
to install packages specifically for Python 2, like
如果您安装了 Python 2.7,我认为您可以使用pip2
并pip2.7
安装专门用于 Python 2 的软件包,例如
pip2 install some_pacakge
or
或者
pip2.7 install some_package
And you may use pip3
or pip3.5
to install pacakges specifically for Python 3.
您可以使用pip3
或pip3.5
专门为 Python 3 安装 pacakges。
回答by P M
On my Windows instance - and I do not fully understand my environment - using pip3 to install the kaggle-cli package worked - whereas pip did not. I was working in a conda environment and the environments appear to be different.
在我的 Windows 实例上 - 我不完全了解我的环境 - 使用 pip3 安装 kaggle-cli 包有效 - 而 pip 没有。我在 conda 环境中工作,环境似乎不同。
(fastai) C:\Users\redact\Downloads\fast.ai\deeplearning1\nbs>pip --version
pip 9.0.1 from C:\ProgramData\Anaconda3\envs\fastai\lib\site-packages (python 3.6)
(fastai) C:\Users\redact\Downloads\fast.ai\deeplearning1\nbs>pip3 --version
pip 9.0.1 from c:\users\redact\appdata\local\programs\python\python36\lib\site-packages (python 3.6)
(fastai) C:\Users\redact\Downloads\fast.ai\deeplearning1\nbs>pip --version
pip 9.0.1 来自 C:\ProgramData\Anaconda3\envs\fastai\lib\site-packages (python 3.6)
(fastai) C:\Users\redact\Downloads\fast.ai\deeplearning1\nbs>pip3 --version
pip 9.0.1 来自 c:\users\redact\appdata\local\programs\python\python36\lib\site-packages (python 3.6)
回答by JL Peyret
Given an activated Python 3.6 virtualenv in somepath/venv, the following aliases resolved the various issues on a macOS Sierra where pip insisted on pointing to Apple's 2.7 Python.
鉴于somepath/venv 中激活的 Python 3.6 virtualenv ,以下别名解决了 macOS Sierra 上的各种问题,其中 pip 坚持指向 Apple 的 2.7 Python。
alias pip='python somepath/venv/lib/python3.6/site-packages/pip/__main__.py'
This didn't work so well when I had to do sudo pip
as the root user doesn't know anything about my alias or the virtualenv, so I had to add an extra alias to handle this as well. It's a hack, but it works, and I know what it does:
当我不得不这样做时,这并没有那么好,sudo pip
因为 root 用户对我的别名或 virtualenv 一无所知,所以我不得不添加一个额外的别名来处理这个问题。这是一个黑客,但它有效,我知道它的作用:
alias sudopip='sudo somepath/venv/bin/python somepath/venv/lib/python3.6/site-packages/pip/__main__.py'
background:
背景:
pip3 did not exist to start (command not found) with and which pip
would return /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/pip, the Apple Python.
pip3 不存在以启动(未找到命令),which pip
并将返回/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/pip,Apple Python。
Python 3.6 was installed via macports.
Python 3.6 是通过 macports 安装的。
After activation of the 3.6 virtualenv I wanted to work with, which python
would return somepath/venv/bin/python
激活我想使用的 3.6 virtualenv 后,which python
将返回somepath/venv/bin/python
Somehow pip install
would do the right thing and hit my virtualenv, but pip list
would rattle off Python 2.7 packages.
不知何故pip install
会做正确的事情并击中我的virtualenv,但pip list
会引起Python 2.7 软件包的轰动。
For Python, this is batting way beneath my expectations in terms of beginner-friendliness.
对于 Python,就初学者友好性而言,这远低于我的预期。