Fixing 'ModuleNotFoundError: No module named pip' in Your Virtual Environment
Development3 min read

Fixing 'ModuleNotFoundError: No module named pip' in Your Virtual Environment

You create a fresh virtual environment, activate it with confidence, and type pip install requests. The response? ModuleNotFoundError: No module named 'pip'

This is one of those "gaslighting" errors. You know you installed Python. You know pip comes with Python. So why is your virtual environment acting like it doesn't exist?

In this guide, I’ll explain why ensurepip fails and how to forcefully reinstall the package manager into your isolated environment.

Root Cause Analysis

When you run python -m venv myenv, Python uses a built-in module called ensurepip to bootstrap pip into the new folder. This process fails if:

  1. Broken Base Install: Your system Python installation is corrupted or a "slim" version (common on Linux distros like Debian/Ubuntu) that omits ensurepip.
  2. Permission Issues: The creation script didn't have write access to finish the job.
  3. Upgrade Interruption: An interrupted upgrade of the venv module left it in a zombie state.

The Solution: Step-by-Step

1. The Native Fix (Try This First)

Since you are inside the environment (or pointing to its python executable), try to trigger the bootstrapping module manually.

Activate your environment:

  • Windows: .\myenv\Scripts\activate
  • Mac/Linux: source myenv/bin/activate

Then run:

python -m ensurepip --upgrade

If this works, you'll see "Successfully installed pip...". Problem solved.

2. The get-pip.py Method (The Hammer)

If ensurepip is also missing or broken (returning "No module named ensurepip"), you need to download the installer script directly.

  1. Download the script:

    curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
    

    (Or download manually from the URL if you don't have curl)

  2. Run it using your environment's Python:

    python get-pip.py
    

This script manually fetches the latest pip wheel and installs it into the currently active Python environment.

3. Linux Specifics: The "venv" Package

If you are on Ubuntu or Debian, the default python3 package is often minimal. You usually need to explicitly install the venv tools.

If you see errors creating the environment, run:

sudo apt update
sudo apt install python3-venv python3-pip

Then delete the old environment and recreate it. Repairing a half-baked venv on Linux is rarely worth the effort compared to a fresh creation.

Expert Tip: Check Your Alias

[!TIP] Check which pip vs which python Sometimes pip isn't missing; it's just not mapped. Run which pip (or where pip on Windows). If it returns nothing, but python works, try running commands as a module: python -m pip install <package>. I actually prefer using python -m pip ... in all my scripts. It guarantees you are using the pip associated with that specific python executable, avoiding "Global vs Local" path confusion.

Conclusion

Missing pip in a venv is usually a sign of a lightweight system Python or a suppressed ensurepip module. The get-pip.py script is your universal skeleton key to fix this. Once restored, remember to update it immediately with python -m pip install --upgrade pip.