Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show top level dependencies for a conda managed environment

Tags:

python

conda

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

like image 764
Yuchen Avatar asked Jun 13 '19 16:06

Yuchen


People also ask

Does conda install dependencies?

Conda provides many of the features found in pip, virtualenv, venv and pyenv. However it is a completely separate tool that will manage Python dependencies differently, and only works in Conda environments. Conda analyzes each package for compatible dependencies, and how to install them without conflict.

Does pip list show conda packages?

conda list --explicit does not include any pip -installed packages, while conda list does.

Can I use pip in a conda environment?

Built into Anaconda, conda is a powerful package manager and environment manager that you use with command-line in the Anaconda Prompt for Windows, or in a terminal window for macOS or Linux. pip is the standard package manager for python, meaning you can use it both inside and outside of Anaconda.


1 Answers

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
like image 80
Daniel Ryan Avatar answered Sep 28 '22 09:09

Daniel Ryan