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?
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
...
... libstdcxx-ng libuuid libxml2 libzlib lz4-c lzo ... pluggy psutil ...
1 Ideally this won't involve copy-paste or regex.
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.
conda list
(OP already describes what this one does)|
is the 'pipe' command and sends the output of a previous command as input for the next.awk
"is a utility that enables a programmer to write tiny programs [and] is mostly used for pattern scanning and processing."[1]!/^#/
ignores any comment lines in the output eg the column headers.&& NF
makes sure the line has at least one field of content, ignoring empty lines.{print $1}
prints the content of the line's first column.xargs
prints the outputs of the previous command (which is run on every line) as one line seperated by spaces.