Install a specific python package version using pip

In this article, we will learn how to install a specific package version with pip

Table Of Contents

What is pip?

pip was earlier known as “pyinstall” and later in 2008, it was renamed to “pip” by Ian Bicking.

pip is the standard package manager for Python that helps you to install and manage the packages which are not included in the Python standard libraries.

How to use pip command?

To verify if pip is installed or not, run the below command in Python virtual environment.

Advertisements
pip

It will show all the commands available for pip, like this

Usage:
pip <command> [options]

Commands:
install    Install packages.
download   Download packages.
uninstall  Uninstall packages.
freeze     Output installed packages in requirements format.
inspect    Inspect the python environment.
list       List installed packages.
show       Show information about installed packages.
check      Verify installed packages have compatible dependencies.
config     Manage local and global configuration.
search     Search PyPI for packages.
cache      Inspect and manage pip's wheel cache.
index      Inspect information available from package indexes.
wheel      Build wheels from your requirements.
hash       Compute hashes of package archives.
completion A helper command used for command completion.
debug      Show information useful for debugging.
help       Show help for commands

How to check the pip version?

If you need to check which version of pip is installed, you need to run the below command:

pip --version

It will show the installed version of pip. like this,

pip 22.3 from C:\Program Files\Python311\Lib\site-packages\pip (python 3.11)

How to upgrade or downgrade the pip version?

You can also upgrade or downgrade the pip version as per requirements. To do this you need to first go to the Python application path and need to run the below commands there.

Upgrading the pip to the latest version?

python -m pip install --upgrade pip

Downgrading the pip to the specific version?

python -m pip install pip==[version number]

How to use the pip command to install the different packages?

How to install packages using pip?

You can install various packages using pip command in Python. You can find the different packages at https://pypi.org. Some of the packages are:

  • Django
  • Flex
  • numpy
  • moviepy

How to check which packages are installed?

You can check the installed packages using the below command:

pip list

It will show all the installed packages in Python. Like this,

Package     Version
--------    --------
pip         22.3
setuptools  1111111165.5.0

Now let’s discuss how you can install different packages using “pip” command in Python.

How to install the latest package version of pip?

To install the latest version of a package, you need to run the below command:

Syntax

pip install <package name>

Example

Installing the package “Django”

pip install Django

Output will be like

Collecting Django Using cached Django-4.1.3-py3-noneany.whl (8.1 MB)
Collecting asgiref<4,>=3.5.2 Using cached asgiref-3.5.2-py3-none-any.whl (22 kB)
Collecting sqlparse>=0.2.2 Using cached sqlparse-0.4.3-py3-noneany.whl (42 kB)
Collecting tzdata Using cached tzdata-2022.6-py2.py3-noneany.whl (338 kB)
Installing collected packages: tzdata, sqlparse, asgiref, Django Successfully installed Django-4.1.3 asgiref3.5.2 sqlparse-0.4.3 tzdata-2022.6

Now if you run the “pip list” command, you will notice that package “django” is installed.

Package     Version
--------    --------
asgiref     3.5.2
Django      4.1.3
pip         22.3
setuptools  65.5.0
sqlparse    0.4.3
tzdata      2022.6

How to install a specific package version using pip

To install the specific version of a package, you need to run the below command:

Syntax

pip install <package name==version>

Example

Installing package “panda” with version “0.1.5”

pip install panda==0.1.5

Output will be like

Collecting panda==0.1.5 Using cached panda-0.1.5.tar.gz (3.1 kB)
Preparing metadata (setup.py) ... done
Collecting requests Using cached requests-2.28.1-py3-noneany.whl (62 kB)
Collecting charset-normalizer<3,>=2 Using cached charset_normalizer-2.1.1- py3-none-any.whl (39 kB) Collecting idna<4,>=2.5 Using cached idna-3.4-py3-none-any.whl (61 kB)
Collecting urllib3<1.27,>=1.21.1 Using cached urllib3-1.26.12-py2.py3- none-any.whl (140 kB) Collecting certifi>=2017.4.17 Using cached certifi-2022.9.24-py3-noneany.whl (161 kB) 
Installing collected packages: urllib3, idna, charset-normalizer, certifi, requests, panda Successfully installed certifi-2022.9.24 charset-normalizer-2.1.1 idna-3.4 panda0.1.5 requests-2.28.1 urllib3-1.26.12

How to install package between two versions using pip

To install a package between two versions, you need to run the below command:

Syntax:

pip install <“package name>=version1,<version2">

Example

pip install "moviepy>=1.0.0,<1.0.2"

Output

Downloading moviepy-1.0.1.tar.gz (373 kB) ---------------------------------------- 374.0/374.0 kB 456.4 kB/s eta 0:00:00 Preparing metadata (setup.py) ... done
Collecting decorator<5.0,>=4.0.2 Using cached decorator-4.4.2-py2.py3- none-any.whl (9.2 kB) 
Collecting tqdm<5.0,>=4.11.2 Using cached tqdm-4.64.1-py2.py3- none-any.whl (78 kB) 
Collecting numpy Using cached numpy-1.23.4-cp311- cp311-win_amd64.whl (14.6 MB) 
Collecting proglog<=1.0.0 Using cached proglog-0.1.10-py3-noneany.whl (6.1 kB) 
Collecting imageio<3.0,>=2.5 Using cached imageio-2.22.3-py3-noneany.whl (3.4 MB) 
Collecting imageio_ffmpeg>=0.2.0 Using cached imageio_ffmpeg-0.4.7- py3-none-win_amd64.whl (22.6 MB) 
Collecting pillow>=8.3.2 Using cached Pillow-9.3.0-cp311-cp311- win_amd64.whl (2.5 MB) 
Collecting colorama Using cached colorama-0.4.6-py2.py3- none-any.whl (25 kB) 
Installing collected packages: pillow, numpy, imageio_ffmpeg, decorator, colorama, tqdm, imageio, proglog, moviepy Running setup.py install for moviepy ... done Successfully installed colorama-0.4.6 decorator-4.4.2 imageio-2.22.3 imageio_ffmpeg-0.4.7 moviepy-1.0.1 numpy-1.23.4 pillow-9.3.0 proglog-0.1.10 tqdm-4.64.1

How to upgrade or downgrade to a specific package version using pip

There are some cases where you are required to upgrade or downgrade the package to a specific version.

So, if you wish to upgrade or downgrade the package to the specific version then you have below options:

  • Uninstall the existing package first and re-install the required version.
  • Upgrade or downgrade the existing package without uninstalling the existing package.

Let’s discuss both above options.

Uninstall existing package and re-install the required version.

Uninstalling the package

To uninstall a package you need to run the below command:

Syntax:

pip uninstall <package name>

Example

When you run the uninstall command,

pip uninstall panda

you will be asked to remove the package, like below

Found existing installation: panda 0.1.5
Uninstalling panda-0.1.5: Would remove: c:\users988\appdata\roaming\python\python311\sitepackages\panda-0.1.5-py3.11.egg-info c:\users988\appdata\roaming\python\python311\sitepackages\panda\*
Proceed (Y/n)?

If you type “Y”, the current package will be uninstalled.

Found existing installation: panda 0.1.5
Uninstalling panda-0.1.5: Would remove: c:\users988\appdata\roaming\python\python311\site-packages\panda-0.1.5-py3.11.egg-info c:\users988\appdata\roaming\python\python311\site-packages\panda\*
Proceed (Y/n)? Y
Successfully uninstalled panda-0.1.5

Now you are ready to install any specific version of the package you need.

Upgrading or downgrading the package without uninstalling the package

To upgrade or downgrade the package without uninstalling, you need to use the below command

Syntax:

pip install [package name==version number] --force-reinstall

Example

pip install Django==4.1.1 --force-reinstall

Output

Collecting Django==4.1.1 Using cached Django-4.1.1-py3-none-any.whl (8.1 MB)
Collecting asgiref<4,>=3.5.2 Using cached asgiref-3.5.2-py3-none-any.whl (22 kB)
Collecting sqlparse>=0.2.2 Using cached sqlparse-0.4.3-py3-none-any.whl (42 kB)
Collecting tzdata Using cached tzdata-2022.6-py2.py3-noneany.whl (338 kB)
Installing collected packages: tzdata, sqlparse, asgiref, Django Attempting uninstall: tzdata Found existing installation: tzdata 2022.6
Uninstalling tzdata-2022.6:
Successfully uninstalled tzdata-2022.6
Attempting uninstall: sqlparse Found existing installation: sqlparse 0.4.3
Uninstalling sqlparse-0.4.3: Successfully uninstalled sqlparse-0.4.3
Attempting uninstall: asgiref Found existing installation: asgiref 3.5.2 Uninstalling asgiref-3.5.2:
Successfully uninstalled asgiref-3.5.2
Attempting uninstall: Django Found existing installation: Django 4.1.3
Uninstalling Django-4.1.3:
Successfully uninstalled
Django-4.1.3 Successfully installed Django-4.1.1 asgiref-3.5.2 sqlparse-0.4.3 tzdata-2022.6

How to install the specific pre-release version of a package using pip

A pre-release version of the package is the version which is not yet been released. If there is a need to install the pre-release version of any package, then you can use the below command:

Syntax:

pip install [package name] --pre

Example

Installing the pre-release version of package “moviepy”

pip install moviepy --pre
Collecting moviepy Using cached moviepy-2.0.0.dev2.tar.gz (400 kB) Preparing metadata (setup.py) ... done
Installing collected packages: moviepy Running setup.py install for moviepy ... done
Successfully installed moviepy-2.0.0.dev2

Install package using pip and ignore installed

If you try to reinstall the existing package, then it will give an error. But if you want to reinstall the existing package again then either you must uninstall it first or you can do it using the below command:

Syntax:

pip install -I [package name]

This command will ignore the existing package and install the package again.

Example

pip install -I moviepy

Output:

Collecting moviepy Downloading moviepy-1.0.3.tar.gz (388 kB) ---------------------------------------- 388.3/388.3 kB 456.6 kB/s eta 0:00:00 Preparing metadata (setup.py) ... done Collecting decorator<5.0,>=4.0.2 Using cached decorator-4.4.2-py2.py3-noneany.whl (9.2 kB)
Collecting tqdm<5.0,>=4.11.2 Using cached tqdm-4.64.1-py2.py3-noneany.whl (78 kB)
Collecting requests<3.0,>=2.8.1 Using cached requests-2.28.1-py3-noneany.whl (62 kB)
Collecting proglog<=1.0.0 Using cached proglog-0.1.10-py3-none-any.whl (6.1 kB)
Collecting numpy>=1.17.3 Using cached numpy-1.23.4-cp311-cp311- win_amd64.whl (14.6 MB)
Collecting imageio<3.0,>=2.5 Using cached imageio-2.22.3-py3-none-any.whl (3.4 MB)
Collecting imageio_ffmpeg>=0.2.0 Using cached imageio_ffmpeg-0.4.7-py3-nonewin_amd64.whl (22.6 MB)
Collecting pillow>=8.3.2 Using cached Pillow-9.3.0-cp311-cp311- win_amd64.whl (2.5 MB)
Collecting charset-normalizer<3,>=2 Using cached charset_normalizer-2.1.1-py3- none-any.whl (39 kB)
Collecting idna<4,>=2.5 Using cached idna-3.4-py3-none-any.whl (61 kB)
Collecting urllib3<1.27,>=1.21.1 Using cached urllib3-1.26.12-py2.py3-noneany.whl (140 kB)
Collecting certifi>=2017.4.17 Using cached certifi-2022.9.24-py3-noneany.whl (161 kB)
Collecting colorama Using cached colorama-0.4.6-py2.py3-noneany.whl (25 kB)
Installing collected packages: urllib3, pillow, numpy, imageio_ffmpeg, idna, decorator, colorama, charset-normalizer, certifi, tqdm, requests, imageio, proglog, moviepy Running setup.py install for moviepy ... done Successfully installed certifi-2022.9.24 charsetnormalizer-2.1.1 colorama-0.4.6 decorator-4.4.2 idna-3.4 imageio-2.22.3 imageio_ffmpeg-0.4.7 moviepy-1.0.3 numpy-1.23.4 pillow-9.3.0 proglog-0.1.10 requests-2.28.1 tqdm-4.64.1 urllib3-1.26.12

Summary

In this article, we learned how we can install Python packages using the pip command.

Pandas Tutorials -Learn Data Analysis with Python

   

Are you looking to make a career in Data Science with Python?

Data Science is the future, and the future is here now. Data Scientists are now the most sought-after professionals today. To become a good Data Scientist or to make a career switch in Data Science one must possess the right skill set. We have curated a list of Best Professional Certificate in Data Science with Python. These courses will teach you the programming tools for Data Science like Pandas, NumPy, Matplotlib, Seaborn and how to use these libraries to implement Machine learning models.

Checkout the Detailed Review of Best Professional Certificate in Data Science with Python.

Remember, Data Science requires a lot of patience, persistence, and practice. So, start learning today.

Join a LinkedIn Community of Python Developers

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top