How to upgrade all Python packages with pip?

Better Stack Team
Updated on January 26, 2023

You can use the pip install command with the --upgrade option to upgrade all packages in your Python environment.

Here's the basic syntax:

pip install --upgrade [package1] [package2] ...

To upgrade all packages, you can use the * wildcard:

pip install --upgrade *

This will upgrade all packages in your environment to the latest version that is compatible with the other packages in your environment.

Alternatively, you can use the pip freeze command to generate a requirements file that lists all the packages in your environment, and then use the pip install -r command to upgrade all the packages at once:

pip freeze > requirements.txt
pip install --upgrade -r requirements.txt

This can be especially useful if you have a lot of packages installed, as it allows you to version control your package dependencies and easily replicate your environment on another machine.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github