Yuchen
Yuchen

Reputation: 33076

Show top level dependencies for a conda managed environment

Just as an example, if I created a new environment.

conda install python
conda create --name foo_environment
conda activate foo_environment
conda install python
conda install jupyter
conda env export > environment.yml

Very obviously, in this case, there are only two top-level dependencies that are added in this environment: python and Jupiter.

I know that we can export the dependencies according to Sharing an environment

conda env export > environment.yml

But see how verbose it is.

name: foo_environment
channels:
  - defaults
  - conda-forge
dependencies:
  - appnope=0.1.0=py37_0
  - attrs=19.1.0=py37_1
  - backcall=0.1.0=py37_0
  - bleach=3.1.0=py37_0
  - ca-certificates=2019.5.15=0
  - certifi=2019.3.9=py37_0
  - dbus=1.13.6=h90a0687_0

...and 70 more lines here. 

Is there a way to only export the top level dependencies? I know I can manually create the yml file like this below. But doing things manually is a bit annoying. Any way to export the top level dependencies automatically?

name: foo_environment
channels:
  - defaults
  - conda-forge
dependencies:
  - python=3.7.3
  - jupyter=1.0.0

Upvotes: 9

Views: 1418

Answers (2)

Daniel Ryan
Daniel Ryan

Reputation: 186

There is a flag --from-history you can use that will only show packages that were explicitly installed and should give you what you want:

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

Upvotes: 8

Andrew Guy
Andrew Guy

Reputation: 9978

There is currently no way of doing this automatically using the conda system.

There is an open issue on the conda GitHub page that explores a similar scenario (finer control over environment exports). As of 18-06-2019 this issue is open.

Upvotes: 0

Related Questions