How can I get the list of package starting with certain character(s) in conda?
How can I get the list of package starting with certain character(s) in conda?
The conda list command is sufficiently expressive to do this. Specifically, examining the usage signature for the command shows that it accepts a regex argument:
$ conda list -h
usage: conda list [-h] [-n ENVIRONMENT | -p PATH] [--json] [-v] [-q]
[--show-channel-urls] [-c] [-f] [--explicit] [--md5] [-e]
[-r] [--no-pip]
[regex]
List linked packages in a conda environment.
Options:
positional arguments:
regex List only packages matching this regular expression.
...
Here are some examples using a regular expression to find packages starting with specific strings.
Packages starting with "sci"
$ conda list '^sci'
# packages in environment at /Users/merv/miniconda3/envs/anaconda_2020_11:
#
# Name Version Build Channel
scikit-image 0.17.2 py38h81aa140_0
scikit-learn 0.23.2 py38h959d312_0
scipy 1.5.2 py38h2515648_0
Packages starting with "num" or "sci"
$ conda list '^(sci|num)'
# packages in environment at /Users/merv/miniconda3/envs/anaconda_2020_11:
#
# Name Version Build Channel
numba 0.51.2 py38h6440ff4_1
numexpr 2.7.1 py38hce01a72_0
numpy 1.19.2 py38h456fd55_0
numpy-base 1.19.2 py38hcfb5961_0
numpydoc 1.1.0 pyhd3eb1b0_1
scikit-image 0.17.2 py38h81aa140_0
scikit-learn 0.23.2 py38h959d312_0
scipy 1.5.2 py38h2515648_0
This should be preferred over using grep because it will preserve the header that conda list outputs.