Quick tutorial on how to update your Python libraries
TLDR
The basic steps to updating your Python packages are:
- Figure out which packages are actually outdated
- Upgrade them
- Lock your new dependencies
How you do this will depend on which package manager you use:
update pip packages
show outdated dependencies
pip list --outdated
upgrade the ones you need
pip install --upgrade requests pandas etc
pin the new versions
pip freeze > requirements.txt
update uv packages
show outdated dependencies
uv tree --outdated --depth 1
update the versions listed in your lockfile
uv lock --upgrade
upgrade the installed versions to what is listed in your new lockfile
uv sync
update poetry packages
show outdated top-level dependencies
poetry show --outdated | grep --file=<(poetry show --tree | grep '^\w' | sed 's/^\([^ ]*\).*/^\1/')
then update your pyproject.toml and install
poetry install
Check your outdated Python libraries
Keeping your Python libraries up to date is crucial for security, performance, and access to the latest features. Whether you're using Windows, Linux, or macOS, updating your Python libraries is a straightforward process. In this guide, we'll walk you through the steps for each operating system.
Before updating, you can check which libraries are installed and their versions by running this command on your command terminal:
pip list --outdated
This command displays a list of installed packages that have newer versions available.
Updating Python libraries on Linux or macOS
-
cd
to your project directory and be sure you activate your project's virtual environment -
To update a specific package:
pip install --upgrade package_name
- To update all outdated packages:
pip list --outdated --format=freeze | cut -d= -f1 | xargs -n1 pip install --upgrade
Updating Python libraries on Windows
-
cd
(or Set-Location) to your project directory and be sure you activate your project's virtual environment -
Use the following command to update a specific package (Replace package_name with the actual library name):
pip install --upgrade package_name
- To update all outdated packages at once, run:
pip list --outdated --format=freeze | ForEach-Object {($_ -split '=')[0]} | ForEach-Object {pip install --upgrade $_}