How to Install Requests in Python

What you’ll build or solve

You’ll install requests into the Python environment you actually run, then confirm Python can import it.

When this approach works best

Installing Requests works best when you want to:

  • Make HTTP calls to an API, like sending a GET request to fetch JSON.
  • Download a web page or file in a script.
  • Follow a tutorial that uses Requests instead of the built-in urllib.

This is a bad idea when you cannot add third-party packages, like some locked-down systems. In that case, use urllib.request from the standard library.

Prerequisites

  • Python 3 installed
  • Access to a terminal (Command Prompt, PowerShell, or a macOS/Linux terminal)

Step-by-step instructions

1) Install Requests with pip

Use python -m pip so pip matches the Python you plan to run.

Option A: Install Requests (most common)

python-m pip install requests

Option B: If your system uses python3

python3-m pip install requests

Option C: Install a specific version

python-m pip install"requests==2.31.0"

What to look for: If you see “Requirement already satisfied,” Requests is already installed in that environment.


2) Confirm the install worked

Import Requests and print its version.

python-c"import requests; print(requests.__version__)"

What to look for:

ModuleNotFoundError: No module named 'requests' usually means you installed Requests for a different Python version than the one you are running.


3) Install in a virtual environment (recommended for projects)

After creating and activating a virtual environment, install Requests there:

python-m pip install requests

Confirm which interpreter you are using:

python-c"import sys; print(sys.executable)"

The path should point inside your virtual environment folder (often .venv).


Examples you can copy

Example 1: Install and verify in one go

python-m pip install requests
python-c"import requests; print(requests.__version__)"

Example 2: Install from a requirements.txt

python-m pip install-r requirements.txt

Example 3: Upgrade Requests

python-m pip install--upgrade requests

Example 4: Verify which Python and pip you are using

python-c"import sys; print(sys.executable)"
python-m pip--version

This confirms that both commands refer to the same interpreter.


Example 5: Install in an already activated virtual environment

python-m pip install requests
python-c"import requests; print(requests.__version__)"
python-c"import sys; print(sys.executable)"

Common mistakes and how to fix them

Mistake 1: Using pip install requests and hitting the wrong Python version

What you might do

pip install requests
python-c"import requests"

Why it breaks

pip can belong to a different interpreter than python.

Corrected approach

python-m pip install requests
python-c"import requests; print(requests.__version__)"

Mistake 2: Installing in one environment, running Python in another

What you might do

  • Install Requests in a virtual environment
  • Run python outside that environment and try to import Requests

Why it breaks

Each environment has its own site-packages, so the import can fail.

Corrected approach

Activate the environment you installed into, then confirm the interpreter path:

python-c"import sys; print(sys.executable)"
python-c"import requests; print(requests.__version__)"

Troubleshooting

If you see ModuleNotFoundError: No module named 'requests', do this:

python-c"import sys; print(sys.executable)"
python-m pip install requests

Make sure you install Requests with the same interpreter you run.

If you see pip: command not found, run pip through Python:

python-m pip install requests

If you see permission errors on macOS/Linux, either use a virtual environment or install for your user:

python-m pip install--user requests

If installation fails, upgrade pip, then retry:

python-m pip install--upgrade pip
python-m pip install requests

If you are on Windows and python opens the Store, use the launcher:

py-m pip install requests
py-c"import requests; print(requests.__version__)"

Quick recap

  • Install with python -m pip install requests
  • Verify with python -c "import requests; print(requests.__version__)"
  • Use a virtual environment for project installs, then install Requests inside it
  • If imports fail, check sys.executable to confirm which Python you are running