HOWTO · Python

Install a Specific Python Package Version With pip

Install and verify an exact Python package version with pip in the intended environment.

On this page

pip installs Python packages; it does not install or switch the Python interpreter itself. To install a particular package version with the interpreter you intend to use, run python -m pip install PACKAGE==VERSION. On Windows, py -m pip install PACKAGE==VERSION can select a registered Python launcher target. Use a virtual environment when the pin belongs to one project.

Install a specific package version with the intended Python interpreter

Replace PACKAGE and VERSION with a distribution name and an available release, for example python -m pip install requests==2.32.3. The == specifier is an exact package-version pin. It is useful when you need a reproducible dependency set, but it is not a command for installing Python 3.12, 3.13, or another interpreter release. Install or select that interpreter first, then invoke its pip module.

Using python -m pip is preferable to an unqualified pip command because it makes the interpreter/package-manager pairing explicit. Check the selected interpreter with python --version and python -m pip --version before changing a project dependency.

Create or select an isolated environment and verify it

Create an environment with python -m venv .venv, then activate it using the command appropriate for your shell. After activation, python --version should identify the interpreter for the project, and python -m pip --version should show a path under .venv. If either command points elsewhere, stop and activate the correct environment instead of pinning a package globally.

Install and verify an exact package version

The following offline fixture creates a small package wheel, installs its exact version into a fresh virtual environment, and prints the installed metadata. In normal work, your package index supplies the wheel; the important part of the install command is demo-package==1.0.0.

rm -rf /tmp/pip-pin-demo
python3 -m venv /tmp/pip-pin-demo
/tmp/pip-pin-demo/bin/python /work/build_wheel.py /tmp/pip-pin-demo/wheelhouse
/tmp/pip-pin-demo/bin/python -m pip install --no-index --find-links /tmp/pip-pin-demo/wheelhouse demo-package==1.0.0
/tmp/pip-pin-demo/bin/python -m pip show demo-package | sed -n '1,3p'

The test runs the setup steps before those exact commands and confirms this output:

Looking in links: /tmp/pip-pin-demo/wheelhouse
Processing /tmp/pip-pin-demo/wheelhouse/demo_package-1.0.0-py3-none-any.whl
Installing collected packages: demo-package
Successfully installed demo-package-1.0.0
Name: demo-package
Version: 1.0.0
Summary: Local package used by the pip version-pin fixture

For a real dependency, verify with python -m pip show PACKAGE or by importing the package in the project. pip normally leaves an installed version alone unless you request --upgrade; adding --upgrade can change transitive dependencies, so review the resolver output and run the project tests afterward.

Record pins in a requirements file

For several dependencies, put one requirement on each line in requirements.txt, such as requests==2.32.3 and urllib3==2.2.2, then install it with python -m pip install -r requirements.txt. Commit that file when it represents a reproducible application environment. A lock file created by your dependency-management tool can be more complete because it records resolved transitive dependencies as well.

Choose exact pins, compatible ranges, or upgrades deliberately

Use an exact pin when a project needs one tested package version. When a library is compatible with a series of releases, a range such as package>=1.0,<2.0 may be more appropriate. Quote operators containing < or > in shells that interpret them, for example python -m pip install 'package>=1.0,<2.0'. Version specifiers follow the PyPA packaging rules, so do not assume every apparent version label is available for every platform or Python release.

Troubleshoot unavailable or incompatible versions

The boundary fixture requests demo-package==9.9.9 from a wheelhouse that contains only version 1.0.0. It exits with status 1 because no matching distribution is available.

/tmp/pip-pin-demo/bin/python -m pip install --no-index --find-links /tmp/pip-pin-demo/wheelhouse demo-package==9.9.9

If a public-index install fails similarly, first check the package name and the versions listed by the index. Then check the package’s Requires-Python metadata and your interpreter version; an older release may not support a modern Python interpreter, and a newer release may not support an old one. Dependency conflicts are a separate resolver problem: change the project constraints deliberately rather than forcing an unrelated old package version. If you actually need a different Python interpreter, install it through your operating system, Python distribution, or version manager, create a new environment from it, and then use that interpreter’s python -m pip.