Question

How to Install a Specific Package Version with pip in Python

pythonmysqlpippypimysql-python

Question

I am using a fresh Python virtual environment created without global site packages, and I want to install version 1.2.2 of MySQL_python. The current version on PyPI is 1.2.3, but I need the older release.

I tried:

pip install MySQL_python==1.2.2

However, after installation, I still see MySQL_python-1.2.3-py2.6.egg-info inside site-packages. Does this mean pip installed the wrong version? Is this specific to this package, or am I misunderstanding how versioned installation works in pip?

Short Answer

By the end of this page, you will understand how to install an exact package version with pip, how to verify what version was actually installed, and why package metadata such as egg-info may sometimes be confusing. You will also learn common troubleshooting steps for version pinning in Python environments.

Concept

When you install Python packages with pip, you can request an exact version by using ==.

pip install package_name==1.2.2

This is called version pinning. It tells pip not to install the latest available version, but the exact one you specified.

This matters because:

  • your code may depend on a specific package behavior
  • a newer version may introduce breaking changes
  • teams often want reproducible environments
  • deployment systems need consistent package versions

In most cases, pip install MySQL_python==1.2.2 is the correct command.

If you still see files mentioning another version, there are a few possibilities:

  • an older or newer package was already present in the environment
  • the package metadata was left behind from a previous install
  • the package's installation script generated confusing metadata
  • you are checking file names instead of asking Python or pip what is installed

The key idea is this: the most reliable way to verify an installed version is to ask pip or Python directly, not just inspect site-packages manually.

Useful verification commands include:

pip show MySQL_python
pip list
pip freeze

In older Python packaging setups, especially with packages that used setup.py and egg-info, the metadata in site-packages could sometimes be misleading. So the command you used is conceptually correct; the confusion is usually about how installation metadata is displayed, not about the syntax for pinning a version.

Mental Model

Think of pip as a librarian and package versions as different editions of the same book.

  • pip install MySQL_python means: "Give me the newest edition."
  • pip install MySQL_python==1.2.2 means: "I want exactly the 1.2.2 edition."

Now imagine the library shelf still has an old label from another edition. That label does not always mean you received the wrong book. It may just mean some packaging metadata or leftover files are still around.

So there are two separate questions:

  1. What did I ask pip to install?
  2. What version is actually active in my environment?

Always confirm using pip show, pip freeze, or importing the package in Python, rather than relying only on folder names.

Take Quiz

Syntax and Examples

The basic syntax for installing a specific version with pip is:

pip install package_name==version

Example:

pip install requests==2.31.0

This installs exactly version 2.31.0 of requests.

You can then verify it:

pip show requests

Example output:

Name: requests
Version: 2.31.0

For your case:

pip install MySQL_python==1.2.2
pip show MySQL_python

If you want to first remove any existing version, you can do:

pip uninstall MySQL_python
pip install MySQL_python==1.2.2

You can also install versions using ranges:

pip install "requests<3"
pip install "requests>=2.28,<2.32"

But if you need one exact release, == is the clearest choice.

Example workflow

python -m venv venv
source venv/bin/activate
pip install requests==2.31.0
pip show requests
pip freeze

This creates an isolated environment, installs a fixed version, and verifies it.

Why this matters

Beginner-friendly rule:

  • Use == when you need an exact version.
  • Use pip show or pip freeze to confirm.
  • Do not rely only on file names inside site-packages.

Step by Step Execution

Consider this example:

pip install requests==2.31.0
pip show requests

Here is what happens step by step:

  1. pip reads the package name: requests
  2. pip reads the version constraint: ==2.31.0
  3. pip searches available distributions that match exactly 2.31.0
  4. pip downloads the matching package
  5. pip installs it into the active environment
  6. pip show requests reads the installed metadata and prints the installed version

Now a Python-based verification example:

import requests
print(requests.__version__)

Step by step:

  1. Python imports the installed requests package
  2. The package exposes its version through __version__
  3. Python prints the actual imported version

For an older package like MySQL_python, version reporting may depend on the package, but the same idea applies: use package metadata tools or import checks rather than directory names.

Traceable troubleshooting sequence

pip uninstall MySQL_python
pip install MySQL_python==1.2.2
pip show MySQL_python
pip freeze | grep -i mysql

This sequence helps you:

  • remove any previous install
  • reinstall the exact version
  • inspect what pip believes is installed
  • check whether a different MySQL-related package is also present

Real World Use Cases

Installing specific package versions is common in real projects.

1. Reproducing a production environment

A deployed app may work only with a tested dependency version.

pip install Django==4.2.11

2. Avoiding breaking changes

A new library release may change behavior or remove APIs.

pip install "urllib3<2"

3. Matching a tutorial, course, or legacy codebase

Older learning material may depend on an earlier version.

pip install Flask==2.0.3

4. Debugging dependency issues

If a bug appears after upgrading, developers often reinstall a known-good version.

pip install pandas==2.1.4

5. Team consistency with requirements files

Projects often pin versions so every developer uses the same package set.

requests==2.31.0
pytest==8.2.2

Then install with:

pip install -r requirements.txt
Take Quiz

Real Codebase Usage

In real codebases, developers rarely install packages manually one by one forever. Instead, they use repeatable dependency management patterns.

Version pinning in requirements.txt

Django==4.2.11
requests==2.31.0
mysqlclient==2.2.4

This ensures everyone installs the same versions.

Using constraints for compatibility

Sometimes developers allow a safe version range instead of one exact version.

requests>=2.28,<3.0

Clean environment setup

A common pattern is:

python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

This avoids conflicts from globally installed packages.

Validation and troubleshooting

Developers often check installed packages with:

pip list
pip freeze
pip show package_name

Upgrade and reinstall patterns

If metadata seems inconsistent, a real project often uses:

pip uninstall package_name
pip install package_name==desired_version

Locking exact versions for CI

Continuous integration systems need deterministic installs. Exact pins reduce surprises between local development and automated tests.

Important practical note

Older packages such as MySQL_python come from an earlier era of Python packaging. In modern Python projects, developers usually prefer actively maintained replacements when possible, but the version pinning technique with pip is the same.

Common Mistakes

1. Checking folder names instead of installed metadata

Beginners often inspect site-packages and assume a folder name tells the whole story.

Better approach:

pip show MySQL_python
pip freeze

2. Installing into the wrong environment

You may think you are using the virtual environment, but pip may belong to another Python installation.

Safer command:

python -m pip install MySQL_python==1.2.2

This makes sure pip matches the current Python interpreter.

3. Forgetting to uninstall an existing version first

If an environment already has old metadata or conflicting files, reinstalling can be confusing.

pip uninstall MySQL_python
pip install MySQL_python==1.2.2

4. Using invalid version syntax

Broken example:

pip install MySQL_python=1.2.2

Correct:

pip install MySQL_python==1.2.2

5. Assuming every package reports its version the same way

Some packages expose __version__; some older ones may not. That is why pip show is often the safer check.

6. Ignoring package age and packaging style

Older packages may use egg-info, which can look different from modern dist-info. That does not automatically mean installation failed.

Broken example: wrong interpreter

pip install requests==2.31.0
python app.py

This can fail if pip installs into a different Python than python runs.

Safer version:

python -m pip install requests==2.31.0
python app.py

Comparisons

TaskSyntaxWhen to use
Install latest versionpip install package_nameWhen you want the newest available release
Install exact versionpip install package_name==1.2.2When you need one specific version
Install minimum/maximum rangepip install "package_name>=1.2,<2.0"When several versions are acceptable
Upgrade a packagepip install --upgrade package_nameWhen moving to a newer release
Reinstall cleanlypip uninstall package_name then reinstallWhen troubleshooting conflicts

pip show vs checking site-packages

MethodBest forReliability
pip show package_nameSeeing installed metadataHigh
pip freezeExporting exact installed versionsHigh
Looking in site-packagesManual inspectionMedium to low

Exact pin vs version range

ApproachExampleProsCons
Exact pinrequests==2.31.0ReproducibleLess flexible
Version rangerequests>=2.28,<3More flexibleCan vary across environments
Take Quiz

Cheat Sheet

# Install exact version
pip install package_name==1.2.2

# Safer: use the active Python interpreter
python -m pip install package_name==1.2.2

# Show installed package details
pip show package_name

# List installed packages
pip list

# Output pinned versions
pip freeze

# Remove a package
pip uninstall package_name

Key rules

  • == means exact version
  • use python -m pip when you want to avoid interpreter mismatch
  • verify with pip show or pip freeze
  • do not trust site-packages file names alone
  • old packages may use egg-info; newer ones often use dist-info

Troubleshooting checklist

  1. Activate the correct virtual environment
  2. Run python -m pip install package==version
  3. Run python -m pip show package
  4. If needed, uninstall first and reinstall
  5. Check for conflicting package names or multiple Python installs

FAQ

How do I install a specific package version with pip?

Use:

pip install package_name==version

Example:

pip install requests==2.31.0

Why does pip seem to install a different version than I requested?

Often the confusion comes from leftover metadata, multiple Python environments, or checking folder names instead of using pip show.

How can I confirm what version is actually installed?

Use:

pip show package_name
pip freeze

You can also import the package in Python if it exposes a version attribute.

Should I use pip or python -m pip?

python -m pip is usually safer because it guarantees that pip runs with the Python interpreter you selected.

What does egg-info mean?

egg-info is older package metadata used by older Python packaging tools. Seeing it does not automatically mean the installation is wrong.

Can I install an older package version in a virtual environment?

Yes. That is one of the main reasons to use a virtual environment: it isolates dependencies so you can install the version your project needs.

What if reinstalling still shows the wrong version?

Try uninstalling the package first, verifying the active environment, and then reinstalling with python -m pip install package==version. Also check whether another similarly named package is installed.

Take Quiz

Mini Project

Description

Create a small dependency-check workflow for a Python project. The project simulates a real development task: setting up a virtual environment, installing an exact package version, and verifying that the environment contains the expected dependency. This helps you practice safe package installation and version verification instead of relying on directory names.

Goal

Set up an isolated Python environment, install a pinned package version, and verify the installed version using pip commands and Python code.

Requirements

[ "Create and activate a virtual environment.", "Install an exact version of a package using pip.", "Verify the installed version with pip show or pip freeze.", "Write a short Python script that imports the package and prints its version if available." ]

Take Quiz

Keep learning

Related questions

View more