How to Install specific package versions with pip and Python

In this post you can find how to install a specific version of a package in Python by pip.

Below you can find quick cheat sheet for installing specific version with pip and Python:

pip install specific version

То install certain package version in Python use:

pip install moviepy==1.0.2

pip install between versions

Install package between two versions with pip:

pip install 'moviepy>=1.3.0,<2.0.0'

pip force install specific version

To force installation of Python package and ignore the installed one do:

pip install -Iv moviepy==1.2.2

where:

  • -I - ignore installed package
  • -v - verbose - will give more output
  • -Iv is combining two flags into one

pip downgrade package

Downgrade of Python package is done by using option --force-reinstall:

pip install 'moviepy==2.0.0' --force-reinstall

pip install older version

To install previous or old version of Python packages use the package version:

pip install 'moviepy==2.0.0'

pip install latest version

Use -U option to install the latest version of Python package

pip install numpy -U

pip install version greater than

If you need to install prerelease packages or version greater than we can use --pre and 'moviepy>=1.0.3':

pip install 'moviepy>=1.0.3' --pre

pip list available versions

To list all available versions of given package with pip:

pip index versions numpy

result:

numpy (1.24.1)
Available versions: 1.24.1, 1.24.0, 1.23.5, ... 1.5.0, 1.4.1, 1.3.0
  INSTALLED: 1.20.3
  LATEST:	1.24.1

pip list version of installed package

pip show numpy

result:

Name: numpy
Version: 1.20.3
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email:
License: BSD
Location: /home/user/venv38/lib/python3.8/site-packages
Requires:
Required-by: abc-analysis, altair, basemap, biopython, blis, bokeh..

Check package version

To check which is the installed version of a given Python package use:

from importlib.metadata import version
version('moviepy')

result:

'2.0.0.dev2'

You can read more about pip install here: