packagecondaenvironmentmamba

Get installed package names from Conda


Problem

When setting up repos, I often get lists of many packages from someone piping conda list into a requirements.txt file. Given I have different pinned packages (e.g. python, cuda), I frequently need to install the same packages without the accompanying specified versions. Conda does a great job of finding out what package versions are compatible with your pinned packages if you just hand it a list of package names. Imagine someone has a conda env set up on our shared machine and I want to build my own environment off of theirs. Is there a solution1 (perhaps a mamba/conda property used to build these the conda list output) that I can utilize to just get a list of the packages to install sans their version and channel etc?

Current

Truncated conda list output example:

...
libstdcxx-ng              13.1.0               hfd8a6a1_0    conda-forge
libuuid                   2.38.1               h0b41bf4_0    conda-forge
libxml2                   2.11.4               h0d562d8_0    conda-forge
libzlib                   1.2.13               hd590300_5    conda-forge
lz4-c                     1.9.4                hcb278e6_0    conda-forge
lzo                       2.10              h516909a_1000    conda-forge
...
pluggy                    1.2.0              pyhd8ed1ab_0    conda-forge
psutil                    5.9.5           py311h2582759_0    conda-forge
...

Desired Output:

... libstdcxx-ng libuuid libxml2 libzlib lz4-c lzo ... pluggy psutil ...

1 Ideally this won't involve copy-paste or regex.


Solution

  • Solution

    A revised version of @NamanMadharia's post to avoid headers and simplify it a bit:

    conda list | awk '!/^#/ && NF {print $1}' | xargs

    This doesn't use a conda property, but the conda list output comes in columns and can be manipulated with the above command easily enough.

    Breakdown: