Skip to content

Instantly share code, notes, and snippets.

@jcmgray
Last active March 12, 2019 01:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcmgray/bd514c9a4cbcceb7e0f6250272a219fb to your computer and use it in GitHub Desktop.
Save jcmgray/bd514c9a4cbcceb7e0f6250272a219fb to your computer and use it in GitHub Desktop.
List: (a) pip installed packages that can be found on conda, (b) pip-only installed packages that are outdated.
#!/usr/bin/env python
import subprocess
print("Finding packages conda says are installed by pip...")
conda_raw = subprocess.run(
['conda', 'list'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
).stdout.decode('utf-8')
pip_only_pkgs = {
ln.split(' ')[0]
for ln in conda_raw.split('\n')
if 'pypi' in ln
}
print("Finding packages pip says are outdated...")
pip_raw = subprocess.run(
['pip', 'list', '--outdated'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
).stdout.decode('utf-8')
pip_outdated_pkgs = {
ln.split(' ')[0]
for ln in pip_raw.split('\n')[2:-1]
}
# search conda for pip installed packages
on_conda = []
not_on_conda = []
not_on_conda_and_outdated = []
is_outdated_msg_lookup = {
False: "but is up to date",
True: "and is also outdated!"
}
print("Searching conda for pip installed packages...")
for pkg in pip_only_pkgs:
search_raw = subprocess.run(
['conda', 'search', pkg],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
).stdout.decode('utf-8')
if "No match found for" in search_raw:
not_on_conda.append(pkg)
msg = " - '{}' is not not conda... {}"
outdated = pkg in pip_outdated_pkgs
if outdated:
not_on_conda_and_outdated.append(pkg)
print(msg.format(pkg, is_outdated_msg_lookup[outdated]))
else:
on_conda.append(pkg)
print(f" - '{pkg}' is on conda!")
print()
print("Packages that seem to be pip only at the moment:")
print(" ".join(not_on_conda))
print()
print("Pip only packages that are outdated:")
print(" ".join(not_on_conda_and_outdated))
print()
print("Packages you could uninstall from pip and install on conda:")
print(" ".join(on_conda))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment