python – conda环境是否可以访问“root”环境? (==系统包)?

康达的“根”环境是什么?它只是一个使用(仅)系统包的环境吗?

其他环境是否也使用系统包(我会假设优先考虑他们的重复版本)?

或者我是否需要在我想要使用它们的环境中安装我的所有软件包?

有没有办法将其配置为选项?

我安装了一个系统软件包,但是当我在conda环境中时无法导入它.

最佳答案
根环境就是您启动的环境.您只能访问已在当前conda环境中明确安装的python包.这是我的系统的样子.请注意,python模块搜索列表(sys.path)中的所有路径都位于根conda文件夹中:

jmepple-lm:~ jmeppley$conda env list
# conda environments:
#
anvio                    /Users/jmeppley/anaconda3/envs/anvio
anvio2                   /Users/jmeppley/anaconda3/envs/anvio2
jupyter                  /Users/jmeppley/anaconda3/envs/jupyter
snake                    /Users/jmeppley/anaconda3/envs/snake
root                  *  /Users/jmeppley/anaconda3

jmepple-lm:~ jmeppley$python -c "import sys; print(\"\\n\".join(sys.path))"

/Users/jmeppley/anaconda3/lib/python35.zip
/Users/jmeppley/anaconda3/lib/python3.5
/Users/jmeppley/anaconda3/lib/python3.5/plat-darwin
/Users/jmeppley/anaconda3/lib/python3.5/lib-dynload
/Users/jmeppley/anaconda3/lib/python3.5/site-packages
/Users/jmeppley/anaconda3/lib/python3.5/site-packages/aeosa
/Users/jmeppley/anaconda3/lib/python3.5/site-packages/galaxy_lib-17.5.9-py3.5.egg
/Users/jmeppley/anaconda3/lib/python3.5/site-packages/mmtf_python-1.0.5-py3.5.egg
/Users/jmeppley/anaconda3/lib/python3.5/site-packages/pysftp-0.2.8-py3.5.egg
/Users/jmeppley/anaconda3/lib/python3.5/site-packages/python_dateutil-2.3-py3.5.egg
/Users/jmeppley/anaconda3/lib/python3.5/site-packages/setuptools-27.2.0-py3.5.egg
/Users/jmeppley/anaconda3/lib/python3.5/site-packages/urllib3-1.12-py3.5.egg

切换conda环境时,python现在将从特定于该环境的文件夹中提取python模块:

jmepple-lm:~ jmeppley$source activate snake
(snake) jmepple-lm:~ jmeppley$python -c "import sys; print(\"\\n\".join(sys.path))"

/Users/jmeppley/anaconda3/envs/snake/lib/python35.zip
/Users/jmeppley/anaconda3/envs/snake/lib/python3.5
/Users/jmeppley/anaconda3/envs/snake/lib/python3.5/plat-darwin
/Users/jmeppley/anaconda3/envs/snake/lib/python3.5/lib-dynload
/Users/jmeppley/anaconda3/envs/snake/lib/python3.5/site-packages
/Users/jmeppley/anaconda3/envs/snake/lib/python3.5/site-packages/mmtf_python-1.0.5-py3.5.egg
/Users/jmeppley/anaconda3/envs/snake/lib/python3.5/site-packages/pysftp-0.2.8-py3.5.egg
/Users/jmeppley/anaconda3/envs/snake/lib/python3.5/site-packages/python_dateutil-2.3-py3.5.egg
/Users/jmeppley/anaconda3/envs/snake/lib/python3.5/site-packages/setuptools-27.2.0-py3.5.egg
/Users/jmeppley/anaconda3/envs/snake/lib/python3.5/site-packages/urllib3-1.12-py3.5.egg

如果你想访问python模块,你必须使用conda install XXX(推荐)或pip install XXX在conda环境中显式安装它.

据我所知,没有简单的方法来覆盖这种行为.

注意:对于非python程序,情况并非如此.执行路径中的任何程序将始终可用,优先考虑通过conda安装的程序.这是因为conda安装位置位于PATH的开头.例如:

(snake) jmepple-lm:~ jmeppley$echo $PATH
/Users/jmeppley/anaconda3/envs/snake/bin:/Users/jmeppley/anaconda3/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

转载注明原文:python – conda环境是否可以访问“root”环境? (==系统包)? - 代码日志