Last active
April 17, 2021 22:51
-
-
Save mfansler/08c91077bbf07d8cf3ba6f3d88d2d46e to your computer and use it in GitHub Desktop.
Script to check all Conda environments for a given package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env conda run -n base --no-capture-output python | |
## Usage: conda-list-any.py [PACKAGE ...] | |
## Example: conda-list-any.py numpy pandas | |
import conda.gateways.logging | |
from conda.core.envs_manager import list_all_known_prefixes | |
from conda.cli.main_list import list_packages | |
from conda.common.compat import text_type | |
import sys | |
for pkg in sys.argv[1:]: | |
print("#"*80) | |
print("# Checking for package '%s'..." % pkg) | |
n = 0 | |
for prefix in list_all_known_prefixes(): | |
exitcode, output = list_packages(prefix, pkg) | |
if exitcode == 0 and len(output) > 3: | |
n += 1 | |
print("\n" + "\n".join(map(text_type, output))) | |
print("\n# Found %d environment%s with '%s'." % (n, "" if n == 1 else "s", pkg)) | |
print("#"*80 + "\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment