pip upgrade package: How to Upgrade a Package Using Pip in Python

Table of Contents What is the pip command?How to pip upgrade or update packages by using the command prompt?2. Pip upgrade package to the specific version3. pip upgrade all packages (for both Windows and Linux …

pip upgrade package

What is the pip command?

pip is an abbreviation of preferred installer program that installs packages and libraries in python. Sometimes when we are working on a python-based platform and start getting an error due to outdated versions of packages.

Note: We are using the Anaconda Command prompt to run all the python commands

How to pip upgrade or update packages by using the command prompt?

Here are the methods that will help you to get the complete list of installed packages in the python environment and select one of them to update individually or select all to upgrade.

Get the list of all packages with their version that is installed in the machine.

pip list

Here you will get the list of all installed packages such as below:

(base) C:\Users\aisha>pip list
Package                            Version
---------------------------------- -------------------
alabaster                          0.7.12
anaconda-client                    1.7.2
anaconda-navigator                 2.0.3
anaconda-project                   0.9.1
anyio                              2.2.0
appdirs                            1.4.4
argh                               0.26.2
argon2-cffi                        20.1.0
asn1crypto                         1.4.0
astroid                            2.5
astropy                            4.2.1
async-generator                    1.10
atomicwrites                       1.4.0
attrs                              20.3.0
autopep8                           1.5.6
Babel                              2.9.0
backcall                           0.2.0
backports.functools-lru-cache      1.6.4
backports.shutil-get-terminal-size 1.0.0
backports.tempfile                 1.0
backports.weakref                  1.0.post1
bcrypt                             3.2.0
beautifulsoup4                     4.9.3
bitarray                           1.9.2
bkcharts                           0.2
black                              19.10b0
bleach                             3.3.0
bokeh                              2.3.2
boto                               2.49.0
Bottleneck                         1.3.2
brotlipy                           0.7.0

You can get the list of all outdated packages.

pip list --outdated

here you will get the list of all outdated packages that need to upgrade.


(base) C:\Users\aisha>pip list --outdated
Package                       Version             Latest    Type
----------------------------- ------------------- --------- -----
anyio                         2.2.0               3.3.1     wheel
argon2-cffi                   20.1.0              21.1.0    wheel
astroid                       2.5                 2.8.0     wheel
astropy                       4.2.1               4.3.1     wheel
attrs                         20.3.0              21.2.0    wheel
autopep8                      1.5.6               1.5.7     wheel
Babel                         2.9.0               2.9.1     wheel
beautifulsoup4                4.9.3               4.10.0    wheel
bitarray                      1.9.2               2.3.4     sdist
bleach                        3.3.0               4.1.0     wheel
bokeh                         2.3.2               2.4.0     wheel
certifi                       2020.12.5           2021.5.30 wheel
cffi                          1.14.5              1.14.6    wheel
click                         7.1.2               8.0.1     wheel
cloudpickle                   1.6.0               2.0.0     wheel
comtypes                      1.1.9               1.1.10    sdist
contextlib2                   0.6.0.post1         21.6.0    wheel
cryptography                  3.4.7               3.4.8     wheel
Cython                        0.29.23             0.29.24   wheel
dask                          2021.4.0            2021.9.0  wheel
decorator                     5.0.6               5.1.0     wheel
distributed                   2021.4.0            2021.9.0  wheel

1. Upgrade package by using pip

if you want to upgrade only one package from the list of outdated packages, select and update it. Suppose the notebook is out of date, we will use the below command to update the notebook.

pip install -U notebook

The notebook is updated as showing below.

(base) C:\Users\aisha>pip install -U notebook
Requirement already satisfied: notebook in d:\annaconda\lib\site-packages (6.3.0)
Collecting notebook
  Downloading notebook-6.4.4-py3-none-any.whl (9.9 MB)
     |████████████████████████████████| 9.9 MB 1.1 MB/s

2. Pip upgrade package to the specific version

To update a specific version of the package, use the package version number with the package name 

pip install update jupyter notebook 3

You will get the output as below:

(base) C:\Users\aisha> pip install update jupyter notebook 3
Collecting update
  Using cached update-0.0.1-py2.py3-none-any.whl (2.9 kB)
Requirement already satisfied: jupyter in d:\annaconda\lib\site-packages (1.0.0)
Requirement already satisfied: notebook in d:\annaconda\lib\site-packages (6.4.4)
Collecting 3
  Downloading 3-0.0.0-py3-none-any.whl (1.6 kB)
Requirement already satisfied: ipywidgets in d:\annaconda\lib\site-packages (from jupyter) (7.6.3)

3. pip upgrade all packages (for both Windows and Linux users)

pip upgrade all packages by installing pip-review first. After installation of pip-review, you can further proceed.

pip install pip-review

pip-review has installed

Collecting pip-review
  Downloading pip_review-1.1.0-py3-none-any.whl (7.2 kB)
Requirement already satisfied: pip in d:\annaconda\envs\my-env\lib\site-packages (from pip-review) (21.0.1)
Requirement already satisfied: packaging in d:\annaconda\envs\my-env\lib\site-packages (from pip-review) (20.9)
Requirement already satisfied: pyparsing>=2.0.2 in d:\annaconda\envs\my-env\lib\site-packages (from packaging->pip-review) (2.4.7)
Installing collected packages: pip-review
Successfully installed pip-review-1.1.0

 Now can update all packages by using the below command.

pip-review --interactive

Install the outdated packages one by one or select all to upgrade. Update[A]ll packages by entering “a” or select[Y]es by entering “y” to upgrade packages one by one.

pip-review --interactive
anyio==3.3.1 is available (you have 2.2.0)
Upgrade now? [Y]es, [N]o, [A]ll, [Q]uit y

Now up-gradation start. It may take a while to complete the procedure.  

Upgrade now? [Y]es, [N]o, [A]ll, [Q]uit (y) a
attrs==21.2.0 is available (you have 20.3.0)
autopep8==1.5.7 is available (you have 1.5.6)
Babel==2.9.1 is available (you have 2.9.0)
beautifulsoup4==4.10.0 is available (you have 4.9.3)
bitarray==2.3.4 is available (you have 1.9.2)
bleach==4.1.0 is available (you have 3.3.0)
bokeh==2.4.0 is available (you have 2.3.2)
certifi==2021.5.30 is available (you have 2020.12.5)
cffi==1.14.6 is available (you have 1.14.5)
click==8.0.1 is available (you have 7.1.2)
cloudpickle==2.0.0 is available (you have 1.6.0)
comtypes==1.1.10 is available (you have 1.1.9)
contextlib2==21.6.0 is available (you have 0.6.0.post1)
cryptography==3.4.8 is available (you have 3.4.7)
Cython==0.29.24 is available (you have 0.29.23)
dask==2021.9.0 is available (you have 2021.4.0)
decorator==5.1.0 is available (you have 5.0.6)
distributed==2021.9.0 is available (you have 2021.4.0)
docutils==0.17.1 is available (you have 0.17)
et-xmlfile==1.1.0 is available (you have 1.0.1)

Conclusion

In this article, we are discussing that how to pip upgrade packages in python. This article contains how to get the list of all outdated packages with their versions and update packages individually or pip upgrade all packages by using commands.

Suggested Read: Remove Brackets from list Python

Leave a Comment