Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search anaconda environments for envs where a certain package has been installed

I submitted an issue on an open source python library and received feedback that the devs couldn't reproduce the error. I had installed the package into a conda environment, and I want to figure out what environment(s) I installed the package into so I can try to reproduce the issue in its original environment. The problem is that I have several conda envs to poke through, and my current strategy of "activate an environment -> start python interpreter -> try to import the package -> exit interpreter -> deactivate environment" is getting old.

Is there a simple way to list all environments which contain a certain package? Something like:

conda info --envs --package=PackageName

EDIT: I've figured out how to check if a package is installed in any of my environments. Still doesn't alert me to which environment has the package, just shows me a hit if the package exists:

Continuum/anaconda3/condabin/conda.bat info --envs | awk '{print $1}' | xargs -ix Continuum/anaconda3/condabin/conda.bat list -n x | grep packagename

This is on a windows machine, using a git bash shell, with the working directory set to /c/Users/userName/AppData/Local

EDIT2: Here's my ultimate solution:

echo Continuum/anaconda3/envs/*/lib/site-packages/PACKAGENAME | sed -E 's/[^ ]+envs\/([^/]+)\/lib[^ ]+/\1/g' | tr " " "\n"
like image 602
David Marx Avatar asked Oct 23 '25 07:10

David Marx


1 Answers

What about using Anaconda Navigator, there is a list of installed plugins. (Not sure if that would be any faster, loading packages takes ages there sometimes.)

This could work for even deactivated environments:

# conda env list ## to list all environments
conda list -n myenv packagename

(And probably stupid question: simple grep for package name wouldnt work?)

EDIT: Based on your last edit:

Continuum/anaconda3/condabin/conda.bat info --envs | awk '{if ($1 != "#") {print $1}}' | xargs -ix Continuum/anaconda3/condabin/conda.bat list -n x packagename | grep -B 3 packagename

(-B 3 prints 3 lines before match, modified awk command a bit to skip '#' envs. Added packagename to list, otherwise hack with -B 3 wouldnt work)

like image 192
Dolfa Avatar answered Oct 25 '25 20:10

Dolfa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!