Show top level dependencies for a conda managed environment

痞子三分冷 提交于 2020-12-05 11:24:23

问题


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


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/56584840/show-top-level-dependencies-for-a-conda-managed-environment

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!