Skip to content

Instantly share code, notes, and snippets.

@mfansler
Last active April 17, 2021 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfansler/08c91077bbf07d8cf3ba6f3d88d2d46e to your computer and use it in GitHub Desktop.
Save mfansler/08c91077bbf07d8cf3ba6f3d88d2d46e to your computer and use it in GitHub Desktop.
Script to check all Conda environments for a given package
#!/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