使用Pip将软件包安装到Anaconda Environment [英] Using Pip to install packages to Anaconda Environment
问题描述
conda 4.2.13 MacOSX 10.12.1
conda 4.2.13 MacOSX 10.12.1
我正在尝试将pip
中的软件包安装到使用anaconda创建的新环境(虚拟)中. 在Anaconda文档中,它说的很完美美好的.它的完成方式与virtualenv相同.
I am trying to install packages from pip
to a fresh environment (virtual) created using anaconda. In the Anaconda docs it says this is perfectly fine. It is done the same way as for virtualenv.
激活要放置程序的环境,然后pip安装程序...
Activate the environment where you want to put the program, then pip install a program...
我在Ananconda中创建了一个空环境,如下所示:
I created an empty environment in Ananconda like this:
conda create -n shrink_venv
激活它:
source activate shrink_venv
然后,我可以在终端中看到正在环境(shrink_venv)
中工作的内容.当我尝试使用pip
安装软件包时出现问题:
I then can see in the terminal that I am working in my env (shrink_venv)
. Problem is coming up, when I try to install a package using pip
:
(shrink_venv): pip install Pillow
Requirement already satisfied (use --upgrade to upgrade): Pillow in /Library/Python/2.7/site-packages
所以我可以看到它认为系统级软件包已满足要求.因此,似乎环境无法正常运行,绝对不像文档中所说的那样.我在这里做错什么了吗?
So I can see it thinks the requirement is satisfied from the system-wide package. So it seems the environment is not working correctly, definitely not like it said in the docs. Am I doing something wrong here?
仅需注意,我知道您可以对软件包使用conda install
,但是anaconda的Pillow遇到了问题,因此我想从pip
中获取它,并且由于文档说还可以.
Just a note, I know you can use conda install
for the packages, but I have had an issue with Pillow from anaconda, so I wanted to get it from pip
, and since the docs say that is fine.
which -a pip
的输出:
/usr/local/bin/pip
/Users/my_user/anaconda/bin/pip
**更新**
我看到这是很常见的问题.我发现,conda env在PYTHONPATH中的表现不佳.即使您使用的是conda环境,该系统似乎也总是在PYTHONPATH位置中查找.现在,在使用conda环境时,我总是运行unset PYTHONPATH
,它的效果要好得多.我在Mac电脑上.
** UPDATE **
I see this is pretty common issue. What I have found is that the conda env doesn't play well with the PYTHONPATH. The system seems to always look in the PYTHONPATH locations even when you're using a conda environment. Now, I always run unset PYTHONPATH
when using a conda environment, and it works much better. I'm on a mac.
推荐答案
对于遇到这种情况的其他人,我发现这是最简单的解决方案:
For others who run into this situation, I found this to be the most straightforward solution:
-
运行
conda create -n venv_name
和source activate venv_name
,其中venv_name
是您的虚拟环境的名称.
Run
conda create -n venv_name
andsource activate venv_name
, wherevenv_name
is the name of your virtual environment.
运行conda install pip
.这会将pip安装到您的venv目录.
Run conda install pip
. This will install pip to your venv directory.
找到您的anaconda目录,并找到实际的venv文件夹.它应该在/anaconda/envs/venv_name/
之类的地方.
Find your anaconda directory, and find the actual venv folder. It should be somewhere like /anaconda/envs/venv_name/
.
通过执行/anaconda/envs/venv_name/bin/pip install package_name
安装新软件包.
Install new packages by doing /anaconda/envs/venv_name/bin/pip install package_name
.
现在应该可以使用该虚拟环境的pip成功安装软件包!
This should now successfully install packages using that virtual environment's pip!
这篇关于使用Pip将软件包安装到Anaconda Environment的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!