Python

Fix Python "ModuleNotFoundError: No module named"

The package is missing, or installed for a different Python. Install it with the same Python that runs your code.

Fill these in once
  1. See which Python runs your code
    Terminal
    which python3
  2. Install with that exact Python
    Terminal
    python3 -m pip install requests

    Using a virtual environment? Switch it on first (source .venv/bin/activate). The install name can differ from the import name: import PIL needs pip install pillow.

  1. See which Python runs your code
    Terminal · Ubuntu / Debian
    which python3
  2. Install with that exact Python
    Terminal · Ubuntu / Debian
    python3 -m pip install requests

    Using a virtual environment? Switch it on first (source .venv/bin/activate). The install name can differ from the import name: import PIL needs pip install pillow.

  1. See which Python runs your code
    PowerShell
    Get-Command python, py
  2. Install with that exact Python
    PowerShell
    py -m pip install requests

    Using a virtual environment? Switch it on first (.venv\Scripts\Activate.ps1). The install name can differ from the import name: import PIL needs pip install pillow.