Install a specific version of a Python package using PIP

David Y.

The Problem

How do I install a specific, older version of a Python package using PIP? Will it matter if I have another version already installed?

The Solution

We can install an older version of a specific package by using the following syntax in our PIP command:

pip install requests==2.30.0

The == syntax allows us to specify a version number. We can see which version numbers are available by looking at the release history on the package’s page on PyPI.org.

Note that, on Windows, the package name and version should be surrounded by quotation marks:

pip install "requests==2.30.0"

If a newer version of the package is already installed on our system or in our current virtual environment, we will need to add the --force-reinstall flag to uninstall that version first:

pip install --force-reinstall requests==2.30.0

To ensure that future users of our project install the correct package versions when setting it up, we should create a requirements file. This is a file in our project’s root directory named requirements.txt, which contains a list of requirement specifiers (i.e. package names and versions) on which our project depends. For this example, our requirements file would have one line:

requests==2.30.0

We would then be able to install the correct version of this and any other packages added by running the following PIP command:

pip install -r requirements.txt

Again, we may need to provide the --force-reinstall flag when running this command.

To avoid changing the packages on our entire system for individual Python projects, we can use a virtual environment. This is the recommended way to deal with Python dependencies in most circumstances.

Get Started With Sentry

Get actionable, code-level insights to resolve Python performance bottlenecks and errors.

  1. Create a free Sentry account

  2. Create a Python project and note your DSN

  3. Grab the Sentry Python SDK

pip install --upgrade sentry-sdk
  1. Configure your DSN
import sentry_sdk sentry_sdk.init( "https://<key>@sentry.io/<project>", # Set traces_sample_rate to 1.0 to capture 100% # of transactions for performance monitoring. # We recommend adjusting this value in production. traces_sample_rate=1.0, )

Loved by over 4 million developers and more than 90,000 organizations worldwide, Sentry provides code-level observability to many of the world’s best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.

Share on Twitter
Bookmark this page
Ask a questionJoin the discussion

Related Answers

A better experience for your users. An easier life for your developers.

    TwitterGitHubDribbbleLinkedinDiscord
© 2024 • Sentry is a registered Trademark
of Functional Software, Inc.