Bash/Shell

Pip install specific version of a package

By ayed_amira , on 02/09/2020 , updated on 09/10/2020 , 4 comments - 2 minutes to read
Executing shell commands in python

Pip install specific version :

How to install a specific version of a package ?

Pip is the most popular tool and command used to install third party packages in Python (version 2 and 3). In this tutorial, we will learn how to install a specific version of a Python package with the pip command.

By default, the pip install command installs the latest version of a package. This can be problematic when you want to install a previous version of a package.


The command to list the different versions of a package is as follows :

$ pip install <NAME_PACKAGE>==

For example for the matplotlib package, we have all these versions:

Pip install specific version

To install a specific version of the package, you have to do the following command:

$ pip install <NAME_PACKAGE>==<VERSION>

If you have several packages that you want to install with specific versions, you can insert them in a .txt file (example.txt) like here:

scikit-learn==0.22.1
matplotlib==3.1.3
numpy==1.11.2

Then do the following command:

pip install -r example.txt

If you need more information about pip command : Link

I also list the main options of the pip install command:

--upgrade-strategy <upgrade_strategy> :

Determines how dependency upgrading should be handled [default: only-if-needed]. “eager” – dependencies are upgraded regardless of whether the currently installed version satisfies the requirements of the upgraded package(s). “only-if-needed” – are upgraded only when they do not satisfy the requirements of the upgraded package(s).

--python-version <python_version> :

The Python interpreter version to use for wheel and “Requires-Python” compatibility checks. Defaults to a version derived from the running interpreter. The version can be specified using up to three dot-separated integers (e.g. “3” for 3.0.0, “3.7” for 3.7.0, or “3.7.3”). A major-minor version can also be given as a string without dots (e.g. “37” for 3.7.0).

--force-reinstall

Reinstall all packages even if they are already up-to-date.

Conclusion

If you’re interested in other articles about python or data science, I suggest you to have a look at the Learning section of the site!

You want to know more about data science with python ? you can buy this book (As an Amazon Partner, I make a profit on qualifying purchases) :

See you soon ! 🙂

ayed_amira

I'm a data scientist. Passionate about new technologies and programming I created this website mainly for people who want to learn more about data science and programming :)

Comments

Leave a comment

Your comment will be revised by the site if needed.