Python
PIP
Version Management
Programming
Software Development

Dealing with multiple Python versions and PIP

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Managing multiple Python versions is normal. One project might require Python 3.10, another 3.12, and your operating system may still depend on its own bundled interpreter. The safest habit is to stop thinking of pip as a standalone command and instead tie every package installation to the exact Python interpreter you intend to use.

That one habit prevents most confusion. If you always run python -m pip, you immediately know which interpreter owns the installation.

Why Bare pip Is Risky

Commands such as pip, pip3, python, and python3 do not always point to the same interpreter. Package managers, shell aliases, Windows launcher rules, and virtual environments can all change what those names resolve to.

That is why this is safer than pip install requests:

bash
python3.11 -m pip install requests
python3.12 -m pip list
py -3.11 -m pip install requests

The chosen interpreter is the one running pip, so there is no ambiguity about where packages go.

Use One Virtual Environment Per Project

Once you know which interpreter you want, create a virtual environment for the project. That keeps dependencies isolated and prevents one project's packages from breaking another project or the system Python.

bash
1python3.11 -m venv .venv
2source .venv/bin/activate
3python -m pip install --upgrade pip
4python -m pip install requests
5python --version
6python -m pip --version

On Windows PowerShell, the same flow looks like this:

powershell
py -3.11 -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip

After activation, python and python -m pip refer to the virtual environment automatically.

Pick a Version Management Strategy

If you switch interpreters often, a version manager is worth it.

Common options:

  • 'pyenv on macOS and Linux'
  • the Windows py launcher
  • project tooling such as Poetry or uv layered on top of specific Python versions

The exact tool matters less than the principle: interpreter choice should be explicit and reproducible, not whatever your shell happened to find first.

Verify Interpreter and pip Together

When package installs or imports behave strangely, check both the interpreter and the installer path.

bash
1python --version
2python -m pip --version
3which python
4which pip

On Windows, use where python and where pip instead of which.

python -m pip --version is especially useful because it usually prints the site-packages location, which shows exactly where the installation is happening.

Avoid Mixing Global and Project Installs

A frequent source of pain is installing some packages globally, some inside a virtual environment, and some with a different interpreter entirely.

A cleaner approach is:

  1. install Python versions globally
  2. create project environments per interpreter
  3. install project dependencies only inside the matching environment
  4. reserve global package installs for carefully chosen tooling

That separation keeps debugging manageable.

Watch Out for Editor and Shell Mismatch

Even when your shell is correct, your editor or IDE may be using a different interpreter. If code runs in the terminal but import resolution fails in the editor, check the selected Python interpreter in the IDE.

This is especially common when a project has:

  • several virtual environments
  • a system Python
  • a pyenv shim
  • tool-managed environments such as Poetry's

The interpreter selection inside the editor should point to the same environment you created for the project.

Common Pitfalls

The biggest mistake is running bare pip and assuming it matches the python you care about. Another is installing project dependencies into the system interpreter with sudo pip install, which can break OS tools. Developers also often create a virtual environment with one Python version and then install packages with another interpreter outside the environment. Finally, if the shell and the IDE disagree about which Python is active, import errors can look random until you compare the interpreter paths directly.

Summary

  • Always tie pip to a specific interpreter with python -m pip.
  • Use a virtual environment per project.
  • Choose Python versions explicitly with tools such as python3.11, py -3.11, or a version manager.
  • Verify python --version and python -m pip --version together when debugging.
  • Keep system Python, project environments, and editor interpreter selection aligned.

Course illustration
Course illustration

All Rights Reserved.