Upgrade/update Python Packages with pip
On Windows:
pip install --upgrade <package-name>
On Linux:
sudo -H pip install --upgrade pip
On MacOS:
pip install --upgrade pip
How to Upgrade Python Packages with Pip
Pip is a package manager for Python that allows you to install, uninstall, and manage Python packages. Updating a package using pip is a straightforward process, and can be done in just a few steps:Open a command prompt or terminal window
To update a package using pip, you need to open a command prompt or terminal window on your computer. Depending on your operating system, the steps to do this may vary.Check the version of the package you want to update
Before updating a package, it's a good idea to check the version of the package that you currently have installed. You can do this by running the following command:
pip show <package-name>
Replace Update pip
It's always a good idea to make sure that pip itself is up-to-date before updating any packages. You can update pip by running the following command:
pip install --upgrade pip
Update the package
Once you have verified the current version of the package you want to update and updated pip, you can update the package using the following command:
pip install --upgrade <package-name>
Replace Verify the update
After updating the package, you can verify that the update was successful by running the same command you used to check the version of the package in step 2:
pip show <package-name>
This command should now display the new version of the package that you just installed.
Now you have successfully updated a package using pip. If you encounter any errors during this process, it's a good idea to check the documentation for the package you're updating to see if there are any special instructions you need to follow.How to update all Python packages On Windows

To update all Python packages on Windows, you can use the following command in the Command Prompt:
python -m pip install --upgrade pip && pip freeze where {$_ -notmatch '^(-e\s)'} %{$_.split('==')[0]} %{pip install -U $_}
This command updates pip to the latest version and then installs the latest version of all packages globally. Here is a breakdown of what each part of the command does:
- python -m pip install --upgrade pip: This updates pip to the latest version.
- pip freeze: This lists all installed packages globally.
- where {$_ -notmatch '^(-e|\s)'}: This filters out any packages installed in "editable" mode.
- {$_.split('==')[0]}: This extracts the package names from the list.
- %{pip install -U $_}: This runs pip install -U for each package name, which installs the latest version of each package.
How to update all Python packages On Linux/macOS
To update all Python packages on Linux, you can use the following command in the command line:
sudo pip install --upgrade pip && sudo pip freeze --local grep -v '^\-e' cut -d = -f 1 xargs -n1 sudo pip install -U
This command will first update pip to the latest version, and then it will list all installed packages and install their latest versions one by one. Here is a breakdown of what each part of the command does:
- sudo pip install --upgrade pip: This updates pip to the latest version.
- sudo pip freeze --local: This lists all installed packages in the current environment.
- grep -v '^\-e': This filters out any packages installed in "editable" mode.
- cut -d = -f 1: This extracts the package names from the list.
- xargs -n1 sudo pip install -U: This runs sudo pip install -U for each package name, which installs the latest version of each package.
How to get a list of all the outdated packages in Python
To get a list of all the outdated packages in Python, you can use the following command in the command prompt or terminal:
pip list --outdated
This command will list all installed packages and indicate which ones have a newer version available. The output will show the package name, the currently installed version, and the latest version available.
If you prefer to see only the package names of outdated packages, you can use the following command:
pip list --outdated --format=freeze grep -v '^\-e' cut -d = -f 1
This command filters the output of the pip list --outdated command to show only the package names of outdated packages. The --format=freeze option produces a list of packages in a format that can be easily filtered, while grep -v '^\-e' removes any packages that were installed with the -e option (editable mode). Finally, cut -d = -f 1 extracts only the package name from each line.
Once you have a list of outdated packages, you can use the pip install --upgrade command to update them to their latest version.
Update all packages in a Virtual Environment
To update all packages in a virtual environment on Windows, you can use the following command in the Command Prompt:
pip install --upgrade pip && pip freeze where {$_ -notmatch '^(-e\s)'} %{$_.split('==')[0]} %{pip install -U $_}
This command updates pip to the latest version and then installs the latest version of all packages in the virtual environment. Here is a breakdown of what each part of the command does:
- pip install --upgrade pip: This updates pip to the latest version.
- pip freeze: This lists all installed packages in the current virtual environment.
- where {$_ -notmatch '^(-e|\s)'}: This filters out any packages installed in "editable" mode.
- {$_.split('==')[0]}: This extracts the package names from the list.
- %{pip install -U $_}: This runs pip install -U for each package name, which installs the latest version of each package.
Update all packages in a Pipenv Environment
To update all packages in a Pipenv environment on Windows, you can use the following command in the Command Prompt:
pipenv update
This command updates all packages in the Pipfile.lock file to their latest compatible versions and updates the Pipfile.lock file. Here is a breakdown of what the command does:
pipenv update: This command updates all packages in the Pipfile.lock file to their latest compatible versions and updates the Pipfile.lock file.
Note that this command should be run from the same directory where the Pipfile and Pipfile.lock files are located.
Also, keep in mind that updating all packages at once may sometimes cause compatibility issues with your code. It's a good practice to create a backup of your code and dependencies before updating all packages, and to thoroughly test your code after updating packages.
Related Topics
- Keywords in Python
- Python Operator - Types of Operators in Python
- Python Variables and Data Types
- Python Shallow and deep copy operations
- Python Datatype conversion
- Python Mathematical Function
- Basic String Operations in Python
- Python Substring examples
- How to check if Python string contains another string
- Check if multiple strings exist in another string : Python
- Memory Management in Python
- Python Identity Operators
- What is a None value in Python?
- How to Install a Package in Python using PIP
- How to Uninstall a Package in Python using PIP
- How to call a system command from Python
- How to use f-string in Python
- Python Decorators (With Simple Examples)
- Python Timestamp Examples