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

查看:132
本文介绍了使用 Pip 将软件包安装到 Anaconda 环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

康达 4.2.13MacOSX 10.12.1

我正在尝试将 pip 中的软件包安装到使用 anaconda 创建的全新环境(虚拟)中.在 Anaconda 文档中 它说这是完美的美好的.它的完成方式与 virtualenv 相同.

<块引用>

激活要放置程序的环境,然后pip install一个程序...

我在 Ananconda 中创建了一个空环境,如下所示:

conda create -n shrink_venv

激活它:

源激活shrink_venv

然后我可以在终端中看到我正在我的环境 (shrink_venv) 中工作.问题来了,当我尝试使用 pip 安装软件包时:

(shrink_venv): pip install Pillow需求已经满足(使用--upgrade升级):枕头在/Library/Python/2.7/site-packages

所以我可以看到它认为系统范围的包满足了要求.所以看起来环境没有正常工作,绝对不像文档中所说的那样.我在这里做错了吗?

请注意,我知道您可以将 conda install 用于软件包,但是我遇到了来自 anaconda 的 Pillow 问题,所以我想从 pip,而且因为文档说这很好.

which -a pip 的输出:

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

** 更新 **我看到这是很常见的问题.我发现 conda env 不能很好地与 PYTHONPATH 配合使用.即使您使用的是 conda 环境,系统似乎总是在 PYTHONPATH 位置中查找.现在,我在使用 conda 环境时总是运行 unset PYTHONPATH,并且效果更好.我用的是 mac.

解决方案

对于其他遇到这种情况的人,我发现这是最直接的解决方案:

  1. 运行 conda create -n venv_nameconda activate venv_name,其中 venv_name 是您的虚拟环境的名称.

  2. 运行 conda install pip.这会将 pip 安装到您的 venv 目录.

  3. 找到您的 anaconda 目录,并找到实际的 venv 文件夹.它应该类似于 /anaconda/envs/venv_name/.

  4. 通过执行 /anaconda/envs/venv_name/bin/pip install package_name 安装新包.

现在应该可以使用该虚拟环境的 pip 成功安装软件包!

conda 4.2.13 MacOSX 10.12.1

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.

Activate the environment where you want to put the program, then pip install a program...

I created an empty environment in Ananconda like this:

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). 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?

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.

Output of 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. 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:

  1. Run conda create -n venv_name and conda activate venv_name, where venv_name is the name of your virtual environment.

  2. Run conda install pip. This will install pip to your venv directory.

  3. Find your anaconda directory, and find the actual venv folder. It should be somewhere like /anaconda/envs/venv_name/.

  4. Install new packages by doing /anaconda/envs/venv_name/bin/pip install package_name.

This should now successfully install packages using that virtual environment's pip!

这篇关于使用 Pip 将软件包安装到 Anaconda 环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆