[英]How can I control which Python distribution to pip install a package to when I have Python 2, Python 3, and Anaconda on my computer?
I have the following Python distributions installed on my Windows computer:我的 Windows 计算机上安装了以下 Python 发行版:
Obviously, they all store their libraries in different locations.显然,他们都将自己的库存储在不同的位置。
So, how can I easily make a targeted installation to (a different) one of them each time I need to do so?那么,如何在每次需要时轻松地对其中一个(不同的)进行有针对性的安装?
For example, right now, I am trying to install pytz
to Python 3.4 (IDLE), and pip install
seems to be defaulting to Python 2.7 (IDLE), which is the first distribution of Python I had installed on my computer.例如,现在,我正在尝试将pytz
安装到 Python 3.4 (IDLE),而pip install
似乎默认为 Python 2.7 (IDLE),这是我在计算机上安装的第一个 Python 发行版。
Anaconda Python蟒蛇蟒
If you have Anaconda python installed, it probably will overwrite python command to point to the Anaconda interpreter as default, so does pip.如果您安装了 Anaconda python,它可能会覆盖 python 命令以默认指向 Anaconda 解释器,pip 也是如此。 In that case, all the libraries installed by pip
command will be installed under the Anaconda python library path:在这种情况下,所有通过pip
命令安装的库都将安装在 Anaconda python 库路径下:
$ which python
/home/datafireball/anaconda/bin/python
$ which pip
/home/datafireball/anaconda/bin/pip
$ cat /home/datafireball/anaconda/bin/pip
#!/home/datafireball/anaconda/bin/python
if __name__ == '__main__':
import sys
from pip import main
sys.exit(main())
Default Python2.7默认 Python2.7
If you try to install libraries under default Python2.7, you can specify the pip path like this:如果您尝试在默认 Python2.7 下安装库,您可以像这样指定 pip 路径:
/usr/bin/pip install <libraryname>
In that case, it will use the Python2.7 interpreter to compile the library and it will be installed under default Python2.7 library folder.在这种情况下,它将使用 Python2.7 解释器来编译库并将其安装在默认的 Python2.7 库文件夹下。
Python3蟒蛇3
In my Ubuntu VM, python3 is installed as default but not the pip3.在我的 Ubuntu VM 中,python3 是默认安装的,但没有安装 pip3。 I have to install by doing sudo apt-get install python3-pip
.我必须通过执行sudo apt-get install python3-pip
。 After it is installed, you can use pip3 to install libraries for python3.安装好之后就可以使用pip3来安装python3的库了。
More about PIP ( ReadTheFullManual ):更多关于 PIP ( ReadTheFullManual ):
There are indeed a lot of interesting arguments in pip command itself to let you install package in whatever way you like. pip 命令本身确实有很多有趣的参数,可以让你以任何你喜欢的方式安装包。
For example,例如,
pip install --target
will install the library in specified library, which you can actually using Anaconda pip to install the library to be under default python library... (not sure why would anyone do this) pip install --target
将在指定的库中安装库,您实际上可以使用 Anaconda pip 将库安装到默认的 python 库下......(不知道为什么会有人这样做)
I'm not sure why you need so many different Pythons, but for Anaconda, you should use conda.我不确定为什么你需要这么多不同的 Python,但是对于 Anaconda,你应该使用 conda。
conda install pytz
will install pytz
into your Anaconda Python.将pytz
安装到您的 Anaconda Python 中。
If all you are aiming to do is to have both Python 2 and Python 3 you can do this with conda.如果您的目标是同时拥有 Python 2 和 Python 3,您可以使用 conda 来实现。
conda create -n py27 python=2.7 anaconda
will create a conda environment (similar to a virtualenv but more powerful) with the Python 2.7 version of Anaconda.将使用 Python 2.7 版本的 Anaconda 创建 conda 环境(类似于 virtualenv 但功能更强大)。 You can then activate this with然后你可以激活它
activate py27
See http://continuum.io/blog/anaconda-python-3 .请参阅http://continuum.io/blog/anaconda-python-3 。
You can also use pip
with Anaconda, but using conda is recommended unless the package you need is not available through conda.您也可以将pip
与 Anaconda 一起使用,但建议使用 conda,除非您需要的包无法通过 conda 获得。
For Anaconda go to C:\\Users\\USERNAME\\Anaconda3\\Scripts对于 Anaconda,请转到 C:\\Users\\USERNAME\\Anaconda3\\Scripts
Change these files pip-script.py and pip.exe to pip3-script.py and pip3.exe .将这些文件pip-script.py和pip.exe更改为pip3-script.py和pip3.exe 。
Then add these variables to your system variables.然后将这些变量添加到您的系统变量中。
Voila..!!瞧……!! Your Job is done.你的工作完成了。 Now to install use pip2 for 2.7 and pip3 for anaconda version.现在安装使用 pip2 for 2.7 和 pip3 for anaconda 版本。
(in command prompt)C:\\Python34\\scripts\\pip.exe install pytz (在命令提示符下)C:\\Python34\\scripts\\pip.exe 安装 pytz
this assumes your path is similar to mine.这假设您的路径与我的相似。 I used the default install location for all my pythons(2.7,3.4).我使用了所有 pythons(2.7,3.4) 的默认安装位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.