Skip to content

Instantly share code, notes, and snippets.

@ovelny
Last active August 13, 2019 19:54
Show Gist options
  • Save ovelny/f3575d9beaeeb8d917ead721a7abb5d2 to your computer and use it in GitHub Desktop.
Save ovelny/f3575d9beaeeb8d917ead721a7abb5d2 to your computer and use it in GitHub Desktop.
Upgrade all --user installed pip packages and solve basic dependency conflicts. Use at your own risk.
#!/usr/bin/env python
from subprocess import call, check_call, check_output, PIPE, Popen
def main():
packages = check_output(
'pip freeze --user | awk \'{gsub("=.*","",$1);print}\'', shell=True, text=True
).split()
check_call(f"pip install --user --upgrade {' '.join(packages)}", shell=True)
print("")
print("-----------------------------")
print("| checking for conflicts... |")
print("-----------------------------")
call(["pip", "check"])
proc = Popen(["pip", "check"], stdout=PIPE, text=True)
conflicts = proc.stdout.read().split()
if len(conflicts) > 0:
print("")
print("------------------------------")
print("| solving basic conflicts... |")
print("------------------------------")
for conflict in conflicts:
chars = ["<", ">", "="]
if any(char in chars for char in conflict):
conflict_version_string = conflict.replace(",", "")
check_call(["pip", "install", "--user", conflict_version_string])
print("")
print("-----------------------------------")
print("| checking remaining conflicts... |")
print("-----------------------------------")
call(["pip", "check"])
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment