How to install specific version of Numpy with PIP?

In this post, we will learn how to install a specific version of NumPy using Pip. To install a specific version of NumPy using PIP, use double equal (==) sign. For example, "pip install numpy==1.23.5". 

If you have already installed NumPy, the best option to install a specific version is to first uninstall and then install it.

If you have already installed a specific version of NumPy and want to install another version, use "--force-reinstall" e.g., "pip install --force-reinstall numpy==1.23.5". 

If you have a virtual env and want to override the installation without uninstalling, use "--ignore-installed", e.g., "pip install --ignore-installed numpy==1.23.5".

Let's understand it in detail.

NumPy is Not Already Installed

If you are installing numpy for first time or have uninstalled the previous version, use the following syntax to install a specific version of NumPy.

Syntax

pip install numpy==version

To install NumPy version 1.23.5, use the following- 

pip install numpy==1.23.5

To install version 1.21.5, use the following command:

pip install numpy==1.21.5

NumPy is Already Installed

If you have already installed NumPy and want to install a specific version of it, you can do any of the following options. Note: Please note that each option has some pros and cons.

Option 1: Uninstall existing version and then install specific version

This option is best when you have already installed NumPy. So first uninstall it and then install the specific version.

pip uninstall numpy
pip install numpy==1.23.5

The above command will uninstall the existing version and install NumPy version 1.23.5.

Option 2: Using --force-reinstall

Another way to install a specific version of NumPy (if you have already installed any version) is using --force-reinstall. The --force-reinstall option first uninstall (if already installed) and then install the specific or current version.

pip install --force-reinstall numpy==1.23.5

The above command will install numpy version 1.23.5. 

Option 3: Using --ignore-installed

The --ignore-installed option ignores the already installed package and its dependencies, overwrites installed files.

It's a good option when you are using virtual env. Use the following command:

pip install --ignore-installed numpy==1.23.5

When you are using pip3

If you are using pip3, to install a specific version of Numpy, you can use all the above commands replacing pip by pip3. Look at the following:

# installing numpy version 1.23.5 
pip3 install numpy==1.23.5
# uninstalling the existing version and installing version 1.23.5 of Numpy 
pip3 uninstall numpy
pip3 install numpy==1.23.5
# Using --force-reinstall 
pip3 install --force-reinstall numpy==1.23.5
# Using --ignore-installed option
pip3 install --ignore-installed numpy==1.23.5

We have covered both the cases to install a specific version of Numpy- first when numpy is not installed and the second when numpy is already installed. In the second case, we have seen three different ways to install a specific version. Hope this article provides accurate information. If you find any error or wrong information please post a comment.

Advertisements

Comments