我有一个名为ABC
的项目,我在折叠~/anaconda/envs/ABC
中有一个conda env,我相信它是一个venv,我想使用来自全球网站的一些特定包包。
对于普通的Python安装,可以从venv文件夹中删除no-global-site-package.txt,或者将venv设置为使用global-site-packages,但我没有找到任何在Anaconda做同样的方法。在线文档也没有答案。
如何为Anaconda做这个?
答案 0 :(得分:4)
you cannot do this explicitly in conda, where the principle is that envs are entirely separate.
but the current default behavior of conda
is to allow all global user site-packages to be seen from within environments, as mentioned in this question. so, the default behavior will allow you to do as you wish, but there is no way to allow only "some specific" global packages as requested.
this behavior has caused one or two issues. to avoid it, export PYTHONNOUSERSITE=1
before source activate <your env>
. note that the devs are planning to change the default behavior to set PYTHONNOUSERSITE=1
in 4.4.0 (per the second issue linked).
答案 1 :(得分:1)
万一有人回到现在,对于conda 4.7.12,在export PYTHONNOUSERSITE=True
调用之前输入conda activate
可以为我成功地将conda环境与全局/用户站点包隔离。
另一方面,输入export PYTHONNOUSERSITE=0
可以将conda环境重新引入到全局/用户站点包中。
注意:这代替了先前建议的export PYTHONNOUSERSITE=1
。
答案 2 :(得分:0)
您可以使用PYTHONPATH环境变量。例如
export PYTHONPATH="/Users/me/anaconda/lib/python2.7/site-packages:$PYTHONPATH"
将为每个环境提供对anaconda发行版中所有库的访问权限。虽然有点破坏了环境的目的。如果您想要访问使用home-brew安装的库,您可以添加
export PYTHONPATH=/usr/local/Cellar/another_package/lib/python2.7/site-packages:$PYTHONPATH