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"
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)
If it's a Python package, then a quick and dirty would be
echo Continuum/anaconda3/envs/*/lib/python*/site-packages/packagename
to list every location it is installed (excluding base ). If you only want the name then you could extract it...
echo Continuum/anaconda3/envs/*/lib/python*/site-packages/packagename |\
sed -E 's/[^ ]+envs\/([^/]+)\/lib[^ ]+/\1/g'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.