Skip to content

Instantly share code, notes, and snippets.

@extratone
Forked from hritik5102/python-upgrade-package.md
Last active October 10, 2023 03:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save extratone/6724c1b95846ba9d136f56e1fc8f0421 to your computer and use it in GitHub Desktop.
Save extratone/6724c1b95846ba9d136f56e1fc8f0421 to your computer and use it in GitHub Desktop.
How To Update All Python Packages

Python Package Upgrade Checklist

Get a list of all the outdated packages

$ pip list --outdated

Open a command shell by typing ‘powershell’ in the Search Box of the Task bar
Update All Python Packages On Windows

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

Update All Python Packages On Linux

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

Pip can be used to upgrade all packages on either Windows or Linux:


  1. Output a list of installed packages into a requirements file (requirements.txt):
$ pip freeze > requirements.txt
  1. Edit requirements.txt, and replace all ‘==’ with ‘>=’. Use the ‘Replace All’ command in the editor.

  2. Upgrade all outdated packages:

$ pip install -r requirements.txt --upgrade

Updating All Packages In A Pipenv Environment

The simplest way to update all the unpinned packages in a specific virtual environment created with pipenv is to do the following steps:

Activate the Pipenv shell that contains the packages to be upgraded

$ pipenv shell

Upgrade all packages

$ pipenv update

If a requirements.txt file is not available, you can use the pip show command to output all the requirements of a specified package:

$ pip show <packagename>

Automatically create requirements.txt

You can use the following code to generate a requirements.txt file:

$ pip install pipreqs
$ pipreqs /path/to/project

More info related to pipreqs can be found here. Sometimes you come across pip freeze, but this saves all packages in the environment including those that you don't use in your current project.

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