The pip installation on Windows failed because the python executable and its scripts directory are not correctly configured in your system’s PATH environment variable, preventing Windows from finding and executing pip commands.

Common Causes and Fixes

  1. Python Not Added to PATH During Installation

    • Diagnosis: Open Command Prompt or PowerShell and type python --version. If you get an error like 'python' is not recognized as an internal or external command, operable program or batch file., Python is not in your PATH.
    • Fix:
      • If you have Python installed:
        1. Find your Python installation directory. This is often C:\Users\<YourUsername>\AppData\Local\Programs\Python\PythonXX (where XX is the version, e.g., 310).
        2. You also need the Scripts subdirectory, which contains pip.exe. This would be C:\Users\<YourUsername>\AppData\Local\Programs\Python\PythonXX\Scripts.
        3. Search for "Edit the system environment variables" in the Windows search bar and open it.
        4. Click the "Environment Variables…" button.
        5. Under "System variables" (or "User variables" if you only want it for your user), select the Path variable and click "Edit…".
        6. Click "New" and paste the full path to your Python installation directory (e.g., C:\Users\<YourUsername>\AppData\Local\Programs\Python\Python310).
        7. Click "New" again and paste the full path to your Python Scripts directory (e.g., C:\Users\<YourUsername>\AppData\Local\Programs\Python\Python310\Scripts).
        8. Click "OK" on all open windows to save the changes.
        9. Crucially, close and reopen any Command Prompt or PowerShell windows for the changes to take effect.
        10. Verify by typing python --version and then pip --version.
      • If you need to reinstall Python:
        1. Download the latest Python installer from python.org.
        2. Run the installer. On the first screen, ensure you check the box that says "Add Python X.Y to PATH" (where X.Y is the version number).
        3. Choose "Install Now" or "Customize installation" as preferred.
        4. After installation, open a new Command Prompt and verify with python --version and pip --version.
    • Why it works: The PATH environment variable is a list of directories that Windows searches when you try to run an executable from the command line. By adding Python’s installation and Scripts directories to PATH, you tell Windows where to find python.exe, pip.exe, and other related scripts.
  2. Multiple Python Versions Conflicting

    • Diagnosis: You might have several Python versions installed, and the one in your PATH isn’t the one you intend to use, or its Scripts directory is missing or pointing to the wrong version. Running where python and where pip in Command Prompt can show you all executables found in the PATH and their locations.
    • Fix:
      1. Manually edit the Path environment variable as described in Cause 1, ensuring that the desired Python version’s directory and its Scripts subdirectory are listed before any other Python installations. The order matters; Windows uses the first one it finds.
      2. If you use tools like pyenv-win, ensure your active Python version is set correctly using pyenv global <version> or pyenv local <version>. Then, verify that pyenv has correctly updated your PATH (this is often handled by pyenv itself, but manual checks are good).
    • Why it works: By prioritizing the correct Python installation’s directories at the beginning of the PATH variable, you ensure that python and pip commands resolve to the intended executable.
  3. Corrupted Pip Installation

    • Diagnosis: You can run python --version and pip --version, but pip install <package> fails with strange errors, or pip --version itself gives an error.
    • Fix:
      1. Ensure Python and pip are in your PATH (Cause 1).
      2. Try to upgrade pip using the python -m pip install --upgrade pip command. The -m flag ensures you are using the pip associated with the python executable found in your PATH.
      3. If that fails, you can try to reinstall pip from scratch.
        • Download get-pip.py from bootstrap.pypa.io/get-pip.py.
        • Open Command Prompt, navigate to the directory where you saved get-pip.py.
        • Run python get-pip.py.
    • Why it works: The -m flag bypasses the PATH lookup for pip.exe and instead executes the pip module directly from the Python installation. Reinstalling get-pip.py ensures you have a clean, functional pip installation.
  4. Permissions Issues or Antivirus Interference

    • Diagnosis: pip commands fail with "Access Denied" errors, or installations seem to hang indefinitely. This is less common for standard user installations but can occur in corporate environments or with very aggressive antivirus software.
    • Fix:
      1. Run Command Prompt as Administrator: Right-click on "Command Prompt" or "PowerShell" in the Start menu and select "Run as administrator." Then try your pip command again (e.g., pip install <package>).
      2. Temporarily Disable Antivirus: If running as administrator works, your antivirus might be blocking pip’s access to certain directories. Temporarily disable real-time protection and try pip again. If it works, you’ll need to configure your antivirus to exclude Python’s installation directory (e.g., C:\Users\<YourUsername>\AppData\Local\Programs\Python\Python310) and its Scripts subdirectory.
    • Why it works: Running as administrator grants elevated privileges, overcoming any restrictive file system permissions. Antivirus software might mistakenly flag pip’s operations as malicious activity, and disabling it allows pip to function normally.
  5. Using py Launcher Incorrectly

    • Diagnosis: You might be trying to run pip via the py launcher (e.g., py -m pip install ...) but have an older or misconfigured py.ini file, or the py launcher itself is not correctly installed or configured in your PATH.
    • Fix:
      1. Ensure the py.exe launcher is present in your Python installation’s root directory and that this directory is in your system’s PATH.
      2. If you have a py.ini file (usually in your user profile directory, C:\Users\<YourUsername>\py.ini), check its contents. It can be used to specify default Python versions. Ensure it doesn’t incorrectly direct py to a non-existent or wrong Python installation.
      3. Prefer using python -m pip when possible, as it directly invokes the Python interpreter found in your PATH, which is generally more straightforward than relying on the py launcher’s interpretation.
    • Why it works: The py launcher is a convenient way to manage multiple Python versions, but its configuration can be a source of confusion. Using python -m pip directly ties the pip execution to the Python interpreter Windows finds first in your PATH, simplifying resolution.

After fixing your PATH and ensuring Python and pip are accessible, the next error you might encounter is a ModuleNotFoundError if you try to import a package that hasn’t been installed yet.

Want structured learning?

Take the full Pip course →