简体   繁体   English

在我的 Conda 环境中安装 pip 包的位置?

[英]Where to install pip packages inside my Conda environment?

As I understand it, if I use pip install ___, that package will go to my global version of python.据我了解,如果我使用 pip install ___,该包将转到我的全球版本的 python。 If I change directory to the within my Conda environment then that package will be isolated within the environment.如果我将目录更改为 Conda 环境中的 ,那么该包将在环境中隔离。 Is this correct?这样对吗?

I have searched to try and find where to put the pip packages (within my Conda environment).我已经搜索尝试找到放置 pip 包的位置(在我的 Conda 环境中)。 It used to be that you would install the pip packages in /Anaconda3/envs/venv_name/bin/ .过去,您会在/Anaconda3/envs/venv_name/bin/安装 pip 包。 It appears the bin folder is now located within the Library folder, like this: /Anaconda3/envs/venv_name/Library/bin .看起来bin文件夹现在位于 Library 文件夹中,如下所示: /Anaconda3/envs/venv_name/Library/bin Is the bin folder still the recommended place to put the packages installed by pip? bin文件夹是否仍然是放置pip安装的软件包的推荐位置?

In other words should I be placing the pip installed packages here: /Anaconda3/envs/venv_name/Library/bin ?换句话说,我应该将 pip 安装的软件包放在这里: /Anaconda3/envs/venv_name/Library/bin

No Specification Needed无需规格

Fortunately, one doesn't have to manually designate where to install the packages.幸运的是,您不必手动指定安装软件包的位置。 Instead, if one uses the pip associated with the environment, it will install them to the site-packages directory of env's python .相反,如果使用与环境关联的pip ,它会将它们安装到 env 的pythonsite-packages目录中。

Example例子

 > conda activate venv_name
 
 # check that you are using the right pip
 > which pip
 /Anaconda3/envs/venv_name/bin/pip  # should be something like this

 > pip install <package name>

This will install packages into /Anaconda3/envs/venv_name/lib/python3.7/site-packages/ , or whatever Python version you have install for the env.这会将软件包安装到/Anaconda3/envs/venv_name/lib/python3.7/site-packages/或您为 env 安装的任何 Python 版本中。

Caution: Mixing PyPI and Conda Packages注意:混合 PyPI 和 Conda 包

Be aware that (as @WilliamDIrons pointed out), it is usually preferable to use conda install -n venv_name <package name> instead of pip .请注意(正如@WilliamDIrons 指出的那样),通常最好使用conda install -n venv_name <package name>而不是pip The common practice is to only use pip in a Conda env when the package is not available through a Conda repository.通常的做法是仅在无法通过 Conda 存储库获得包时在 Conda 环境中使用pip It is strongly recommended to read and follow the best practices found in the " Using pip in an environment " documentation.强烈建议阅读并遵循“ 在环境中使用 pip ”文档中的最佳实践。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM