An alternative to conda env export that helps create portable environment
specifications with minimum number of packages.
Conda-export creates environment specifications which contain only top-level
(non-transient) dependencies. It tries to minimize specific version information and
total number of packages, so that the resulting spec maximizes upgradability.
At the same time, it respects specific package versions that were used while creating
the environment. If, at some point, you installed a package with explicit version (e. g.
conda install pytorch=1.9.0), conda-export will include this specific version in
the resulting spec file.
It makes sense to install conda-export into base environment and call it from
there, since it would be weird to install conda into your actual working env.
conda install conda-export -n base -c conda-forgeconda-export -n [env name] -f [optional output file]If -f is not specified, dumps the spec to the console.
This is the exact algorithm that is used to export environment specifications:
conda-leaves← make a dependency graph of all conda packages and select top-level ones. Exclude packages that were installed withpip.versioned_hist← executeconda env export --from-historyto get only those packages that were explicitly installed by user withconda createorconda install. Filter packages to leave only those with explicit version specified.conda_pip← executeconda env exportand get packages that were installed withpipand notconda.pip_leaves← executepip list --not-requiredto get top-level packages from pip's perspective.- Compile the final list as follows:
- conda dependencies:
conda_leaves.union(versioned_hist) - pip dependencies:
conda_pip.intersection(pip_leaves)
- conda dependencies:
conda-export is not suited for creating reproducible
environments. Please use conda-lock with environment specs generated from
conda-export in order to create multi-platform lock files that contain exact package
versions.