2

I create a conda environment without specifying any packages using the following command:

conda create --name test_env

I can then use all the packages in the root environment inside test_env (but they do not appear in the outputs of conda list and conda env export). This is already unexpected to me but the real problems begin when I then install something inside that environment, e.g.:

conda install pywavelets

Afterwards, pywavelets is usable but all the other packages which are no dependencies of pywavelets disappear inside the environment (e.g. pandas). I don't understand why that happens. Does anybody have an explanation for that?

More importantly, what does this mean for best practices for working with conda environments? Should I always create my environments specifying at least python (conda create --name test_env python)? However, then I have to install everything by hand in that environment which is quite cumbersome. So, my idea now is to specify anaconda for all environments I create:

conda create --name test_env anaconda

The disadvantage, however, is that the list of dependencies listed by conda list and conda env export gets unnecessarily long (e.g. even listing the Anaconda Navigator). Does anybody have a better solution for this?

lilaf
  • 359
  • 1
  • 5
  • 10

1 Answers1

4

The reason you can use all the packages from the root environment when you don't specify a Python version during environment creation is because you're actually using the root environment's Python executable! You can check with which python or python -c "import sys; print(sys.executable)". See also my other answer here.

When you install pywavelets, one of the dependencies is (probably) Python, so a new Python executable is installed into your environment. Therefore, when you run Python, it only picks up the packages that are installed in the test_env.

If you want all of the packages from another environment, you can create a file that lists all the packages and then use that file to create a new environment, as detailed in the Conda docs: https://conda.io/docs/user-guide/tasks/manage-environments.html#building-identical-conda-environments To summarize

conda list --explicit > spec-file.txt
conda create --name myenv --file spec-file.txt

or to install into an existing environment

conda install --name myenv --file spec-file.txt

Since that's just a text file, you can edit and remove any packages that you don't want.

darthbith
  • 18,484
  • 9
  • 60
  • 76
  • I know that I can create an identical environment with the commands you explained above, that's not what I want to do here. I was just very surprised by the behavior when creating an environment without specifying anything. That's clear now, so thanks for the explanation! – lilaf Aug 25 '17 at 07:40
  • The reason I mentioned the identical environments is because you asked if you had to specify all the packages you wanted by hand. The answer is yes, unless you use a file that contains the appropriate definitions. – darthbith Aug 25 '17 at 12:26