问题
What is the 'root' environment in conda? Is it just an environment which uses (only) the system packages?
Do other environments use the system packages as well (I would assume giving preference to their versions of duplicates)?
Or would I need to install all of my packages in the environment where I want to use them?
Is there a way of configuring this as an option?
I have a system package installed but I can't import it when I'm in a conda environment.
回答1:
The root environment is just the environment you start in. You only have access to python packages that you've explicitly installed in the current conda environment. Here is what my system looks like. Note that all the paths in the python module search list (sys.path) are in the root conda folder:
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
When you switch conda environments, python will now pull python modules from folders specific to that environment:
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
If you want access to a python module, you'll have to instal it explicitly in that conda environment with conda install XXX
(recommended) or pip install XXX
.
As far as I know, there is no easy way to override this behavior.
NOTE: This is not true for non-python programs. Any programs in your execution path will always be available, with preference given to programs installed via conda. This is because the conda install location is at the start of your PATH. EG:
(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
来源:https://stackoverflow.com/questions/41640056/do-conda-environments-have-access-to-root-environment-system-packages