Conda env export --from-history not behaving as expected

I built a conda environment using these steps:

conda create -n torch-cuda
conda activate torch-cuda
conda install pytorch=2.1.0=py3.11_cuda11.8_cudnn8.7.0_0 pytorch-cuda=11.8 -c pytorch -c nvidia
conda config --set channel_priority disabled
conda install h5py jupyter matplotlib pandas -c conda-forge

So, packages are being installed from 4 different channels: default, conda-forge, nvidia, and pytorch as confirmed by running

conda list

However, when I run

conda env export --from-history > ENV.yml

This is what I get:

name: torch-cuda
  - defaults
  - pytorch-cuda=11.8
  - pytorch==2.1.0=py3.11_cuda11.8_cudnn8.7.0_0
  - h5py
  - jupyter
  - matplotlib
  - pandas
prefix: /lusr/opt/miniconda/user-envs/pgoetz/torch-cuda

I mean, yes, it is only listing packages that I explicitly installed, but I don’t see any way that someone could recreate the environment from this yaml file, because, for example, the version of pytorch installed here is only available through the pytorch channel, which isn’t mentioned in the environment file. Moreover, h5py, jupyter, matplotlib, and pandas are all being installed from the conda-forge channel, also not mentioned.

The alternative way to export an environment:

conda env export > ENV2.yaml

creates a file which does list all the channels used, followed by an overwhelming list of (290) installed packages. Surely there is a middle ground here? I’m 100% not following why the –from-history option causes the channels used to not be referenced in the yaml output file, since without this it’s an incomplete resource.

This has been brought up on this feature request in the conda repository:

I think this behavior deviates enough from what one would expect to warrant its own bug report though.

One way to work around this would be manually specifying the channels like so:

conda env export --from-history -c pytorch -c defaults

That works but admittedly isn’t ideal. There’s also an open epic on the GitHub project highlighting all the current issues with conda env export:

1 Like