Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save v1k0d3n/b04a2570817079c675c0f8e6db36acbf to your computer and use it in GitHub Desktop.
Save v1k0d3n/b04a2570817079c675c0f8e6db36acbf to your computer and use it in GitHub Desktop.
Hot to update all Python packages with pip

How To Update All Python Packages

List Outdated Packages

pip list --outdated

Update All Python Packages

Windows

pip freeze | %{$.split('==')[0]} | %{pip install --upgrade $}

Linux

To upgrade all packages using pip with grep on Ubuntu Linux

pip3 list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip3 install -U

To upgrade all packages using pip with awk on Ubuntu Linux

pip3 list -o | cut -f1 -d' ' | tr " " "\n" | awk '{if(NR>=3)print}' | cut -d' ' -f1 | xargs -n1 pip3 install -U

Update Specific Packages On Windows Or Linux

  1. Freeze packages

    pip freeze > requirements.txt
    
  2. Edit requirements.txt (set the versions you need for your project)

  3. Upgrade to the newer/older versions you've setted

    pip install -r requirements.txt --upgrade
    

References

https://www.activestate.com/resources/quick-reads/how-to-update-all-python-packages/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment