使用 Pip 将软件包安装到 Anaconda 环境 - Using Pip to install packages to Anaconda Environment

问题:

conda 4.2.13 MacOSX 10.12.1康达 4.2.13 MacOSX 10.12.1

I am trying to install packages from pip to a fresh environment (virtual) created using anaconda.我正在尝试将pip中的软件包安装到使用 anaconda 创建的新环境(虚拟)中。 In the Anaconda docs it says this is perfectly fine. 在 Anaconda 文档中,它说这完全没问题。 It is done the same way as for virtualenv.它的完成方式与 virtualenv 相同。

Activate the environment where you want to put the program, then pip install a program...激活要放置程序的环境,然后pip install一个程序...

I created an empty environment in Ananconda like this:我在 Ananconda 中创建了一个空环境,如下所示:

conda create -n shrink_venv

Activate it:激活它:

source activate shrink_venv

I then can see in the terminal that I am working in my env (shrink_venv) .然后我可以在终端中看到我正在我的 env (shrink_venv) Problem is coming up, when I try to install a package using pip :问题来了,当我尝试使用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?我在这里做错了吗?

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.请注意,我知道您可以将conda install用于软件包,但是我遇到了来自 anaconda 的 Pillow 问题,所以我想从pip获取它,因为文档说这很好。

Output of which -a pip : which -a pip输出:

/usr/local/bin/pip
/Users/my_user/anaconda/bin/pip

** UPDATE ** I see this is pretty common issue. ** 更新 ** 我认为这是很常见的问题。 What I have found is that the conda env doesn't play well with the PYTHONPATH.我发现 conda env 不能很好地与 PYTHONPATH 配合使用。 The system seems to always look in the PYTHONPATH locations even when you're using a conda environment.即使您使用的是 conda 环境,系统似乎总是在 PYTHONPATH 位置中查找。 Now, I always run unset PYTHONPATH when using a conda environment, and it works much better.现在,我在使用 conda 环境时总是运行unset PYTHONPATH ,而且效果更好。 I'm on a mac.我在 mac 上。


解决方案:

参考一: https://stackoom.com/question/2mHgE
参考二: Using Pip to install packages to Anaconda Environment
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章