可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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:
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:
Usage:
pip <command> [options]
which is the same message I get when I type just 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
?
回答1:
Your pip
is soft link to the same executable file path with pip3
.
you can use below commands to check where your pip
and pip3
real paths are:
$ ls -l `which pip`
$ ls -l `which pip3`
you may also use below commands to know more details:
$ pip show pip
$ pip3 show pip
When we installed different version of python, we may do such soft links to
- set default pip to some version.
- make different links for different versions.
it is same situation about python
, python2
, python3
Below for who interested in how it happens in different case:
- MacOS/Homebrew
- Fedora/CentOS
- Debian/Ubuntu
回答2:
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
.
On your system you have now pip, pip2 and pip3.
If you want you can change pip to point to pip2 instead of pip3.
回答3:
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
.
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.
回答4:
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.
回答5:
If you installed Python 2.7, I think you could use pip2
and pip2.7
to install packages specifically for Python 2, like
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.
回答6:
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:
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.
回答7:
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.
(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)