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
pipwhat 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
Mental Model
Think of pip as a librarian and package versions as different editions of the same book.
pip install MySQL_pythonmeans: "Give me the newest edition."pip install MySQL_python==1.2.2means: "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:
- What did I ask
pipto install? - 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.
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
Step by Step Execution
Consider this example:
pip install requests==2.31.0
pip show requests
Here is what happens step by step:
pipreads the package name:requestspipreads the version constraint:==2.31.0pipsearches available distributions that match exactly2.31.0pipdownloads the matching packagepipinstalls it into the active environmentpip show requestsreads the installed metadata and prints the installed version
Now a Python-based verification example:
import requests
print(requests.__version__)
Step by step:
- Python imports the installed
requestspackage - The package exposes its version through
__version__ - 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.
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
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.
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 ; some older ones may not. That is why is often the safer check.
Comparisons
| Task | Syntax | When to use |
|---|---|---|
| Install latest version | pip install package_name | When you want the newest available release |
| Install exact version | pip install package_name==1.2.2 | When you need one specific version |
| Install minimum/maximum range | pip install "package_name>=1.2,<2.0" | When several versions are acceptable |
| Upgrade a package | pip install --upgrade package_name | When moving to a newer release |
| Reinstall cleanly | pip uninstall package_name then reinstall | When troubleshooting conflicts |
pip show vs checking site-packages
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 pipwhen you want to avoid interpreter mismatch - verify with
pip showorpip freeze - do not trust
site-packagesfile names alone - old packages may use
egg-info; newer ones often usedist-info
Troubleshooting checklist
- Activate the correct virtual environment
- Run
python -m pip install package==version - Run
python -m pip show package - If needed, uninstall first and reinstall
- 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?
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." ]
Keep learning
Related questions
@staticmethod vs @classmethod in Python Explained
Learn the difference between @staticmethod and @classmethod in Python with clear examples, use cases, mistakes, and a mini project.
Call a Function by Name in a Python Module
Learn how to call a function by name in a Python module using strings, getattr, and safe patterns for dynamic function dispatch.
Catch Multiple Exceptions in One except Block in Python
Learn how to catch multiple exceptions in one Python except block using tuples, with examples, mistakes, and real-world usage.