Skip to main content

How to Solve "ModuleNotFoundError: No module named 'pip'" in Python

The error ModuleNotFoundError: No module named 'pip' in Python indicates that the pip package manager is not installed or not accessible in your current Python environment. pip is essential for installing and managing other Python packages.

This guide provides a step-by-step guide to diagnose and fix this problem, covering various scenarios and operating systems.

Understanding the Error: pip and Module Installation

  • pip: pip is the standard package installer for Python. It's used to download and install packages from the Python Package Index (PyPI) and other sources.
  • ModuleNotFoundError: This error means Python can't find the pip module when you try to use it (e.g., when running pip install ...).
  • Why is pip missing?: Most Python installations include pip, so it means that either pip wasn't properly installed, or it is not present in your system's PATH.

The ensurepip module, included with Python 3.4 and later, is the recommended way to bootstrap pip if it's missing:

python -m ensurepip --upgrade  # Use your system's default Python
python3 -m ensurepip --upgrade # Explicitly use Python 3
py -m ensurepip --upgrade # Windows: Use the py launcher
  • python -m ensurepip: This runs the ensurepip module, which will install pip if it's not already present, or upgrade it if it's outdated.
  • --upgrade: This option ensures that pip (and related tools like setuptools and wheel) are upgraded to the latest versions. This is highly recommended.
  • Use the command that corresponds to the version of Python you are using.

Solution 2: Using get-pip.py (If ensurepip Fails)

If ensurepip doesn't work (which is rare), you can use the get-pip.py script:

  1. Download get-pip.py: Download the script from https://bootstrap.pypa.io/get-pip.py (right-click and "Save As...").

  2. Run the script:

    python get-pip.py  # Or python3 get-pip.py, or py get-pip.py

    You might need administrator/superuser privileges (e.g., sudo python3 get-pip.py on Linux/macOS).

Solution 3: Using Your Operating System's Package Manager

If you installed Python through your operating system's package manager (e.g., apt on Debian/Ubuntu, brew on macOS), you might be able to install pip using that same package manager. This is generally less preferred than using ensurepip or get-pip.py because it might not give you the latest version of pip, but it can be a useful fallback.

  • Debian/Ubuntu:

    sudo apt update
    sudo apt install python3-pip python3-venv
  • macOS (Homebrew):

    brew install python  # This installs Python and pip
  • Fedora:

    sudo dnf update
    sudo dnf install python3-pip python3-wheel
  • CentOS/RHEL:

    sudo yum update
    sudo yum install python3 python3-pip
  • Arch Linux:

    sudo pacman -S python-pip

Solution 4: Virtual Environments (Best Practice)

It's highly recommended to use virtual environments for Python development. Virtual environments isolate your project's dependencies, preventing conflicts between projects. Crucially, venv (the standard virtual environment module) automatically includes pip. So, if you create a virtual environment, you'll always have pip available within that environment.

# Create a virtual environment:
python3 -m venv venv # Or python -m venv venv, or py -m venv venv

# Activate the environment:
# macOS / Linux:
source venv/bin/activate

# Windows (cmd.exe):
venv\Scripts\activate.bat

# Windows (PowerShell):
venv\Scripts\Activate.ps1

# Now pip is available within the activated environment:
pip --version # Should work!
pip install <some_package> # Install packages into the environment

Troubleshooting: PATH Issues

Even if pip is installed, you might get an error if the directory containing the pip executable is not in your system's PATH environment variable. This is less common if you've used ensurepip or a virtual environment, but it can happen. If the commands above don't work, make sure to add Python and pip to the PATH.

Reinstalling Python (Last Resort)

If all else fails, and you've tried everything else, you might consider reinstalling Python. This is rarely necessary, but it can sometimes fix deeply corrupted installations. Download the latest version from python.org and follow the installation instructions for your operating system. Be sure to back up any important data before reinstalling!

Conclusion

The ModuleNotFoundError: No module named 'pip' error means that the pip package manager is not properly installed or accessible.

  • The recommended solution is to use python -m ensurepip --upgrade to install or upgrade it.
  • Using virtual environments is strongly encouraged, as they include pip by default and prevent dependency conflicts.

If you've tried these steps and are still having trouble, double-check your Python installation and PATH settings, and consider reinstalling Python as a last resort.