ScreenshotNeo

BlogHow-to

3 Ways to Install the Python Requests Library

Install Requests with pip, isolate it in a virtual environment, or work from source. This guide covers Windows, macOS, Linux, offline installs, and common fixes.

By the ScreenshotNeo team29 September 202610 min read

3 Ways to Install the Python Requests Library

The usual way to install the Python Requests library is with python -m pip install requests. On macOS and Linux, use python3 -m pip install requests if that is the command for your Python 3 interpreter; on Windows, use py -m pip install requests. For a project, create and activate a virtual environment first so the package is installed for that project’s interpreter.

This guide covers three routes: installing a published package from PyPI, installing into a virtual environment, and installing Requests from its source checkout. It also explains how to verify the installation, handle offline or restricted networks, and fix common interpreter and pip errors.

1. Install Requests from PyPI with pip

PyPI is the package registry for published Requests releases. Open a terminal and run the command matching the Python interpreter you will use to run your program:

# macOS or Linux
python3 -m pip install requests

# Windows
py -m pip install requests

The cross-platform form in the Requests documentation is python -m pip install requests. The important part is -m pip: it runs pip through the selected Python interpreter, helping avoid installing the package for one Python and then running your script with another. The Requests documentation and Python Packaging User Guide document these installation commands. Requests installation instructions · Python Packaging User Guide.

Check that the installation worked

Use the same launcher you used to install the package. The following prints the installed Requests version and its module path:

# macOS or Linux
python3 -c "import requests; print(requests.__version__); print(requests.__file__)"

# Windows
py -c "import requests; print(requests.__version__); print(requests.__file__)"

Then try a small script that makes an HTTP request. This example uses the Requests API; it contacts the public site and therefore requires network access:

import requests

response = requests.get("https://example.com", timeout=15)
response.raise_for_status()
print(response.status_code)
print(response.url)

Save it as check_requests.py and run it with the same interpreter, such as python3 check_requests.py or py check_requests.py. A successful import proves that Python can find Requests. A successful HTTP call additionally depends on DNS, network access, TLS certificates, and the remote server.

Install a particular release

To request a specific version, add a version specifier. Substitute a version that your project has chosen:

python -m pip install "requests==2.32.5"

For reproducible project setup, record dependency versions in a requirements file and install from it:

# requirements.txt
requests==2.32.5
python -m pip install -r requirements.txt

Pinning is a project maintenance choice: update and review the pin when you intend to move to another release. Do not assume a version shown in an example will be the newest when you read this.

2. Install Requests in a virtual environment

A virtual environment gives a project its own package installation area. It helps keep project dependencies separate from other projects and from packages managed by the operating system. This is the recommended route for most application projects and for learning exercises.

Create and activate the environment

From your project directory, create an environment named .venv:

python -m venv .venv

Activate it using the command for your shell and operating system:

# macOS or Linux, bash or zsh
source .venv/bin/activate

# Windows, Command Prompt
.venv\Scripts\activate.bat

# Windows, PowerShell
.venv\Scripts\Activate.ps1

When activation succeeds, many shells show (.venv) in the prompt. Install Requests into the active environment:

python -m pip install requests

Verify which Python is active and import the library:

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

The path printed by sys.executable should point inside your project’s .venv directory. If it points elsewhere, the environment may not be active, or your IDE may be configured to use a different interpreter. Configure the IDE to use the Python executable inside .venv.

Use the environment without activating it

Activation only adjusts shell command lookup; it is not required. You can invoke the environment’s interpreter directly, which is useful in scripts or automation:

# macOS or Linux
.venv/bin/python -m pip install requests
.venv/bin/python your_script.py

# Windows
.venv\Scripts\python.exe -m pip install requests
.venv\Scripts\python.exe your_script.py

Keep the environment directory out of version control in most projects, and share a dependency file such as requirements.txt instead. Each developer or deployment environment can recreate the virtual environment from that file.

3. Install Requests from source

Installing from source is useful when you need to inspect or modify the project code, test a change, or work from a particular repository revision. The official Requests instructions describe cloning its public repository and installing the checkout with pip.

git clone https://github.com/psf/requests.git
cd requests
python -m pip install .

For application use, do this inside an activated virtual environment. If you are developing Requests itself and want edits in the checkout to be reflected by the installed package, use pip’s editable mode:

python -m pip install --editable .

Editable installs are intended for active development. They link the working source directory into the environment, so you can change files without reinstalling after every edit. A regular python -m pip install . installs the checkout as a package; if you later change source files, reinstall as needed.

Another source distribution option is to download a source archive from the project’s release page and install that local archive with pip. Check that the archive is from a release or repository location you trust, and use the same interpreter-bound pip command used elsewhere in this guide.

Choose the right installation method

Method Best for Command shape
PyPI with pip A quick install of a released package python -m pip install requests
Virtual environment Projects that need isolated dependencies Create and activate .venv, then install with pip
Source checkout Inspecting or developing Requests itself Clone repository, then python -m pip install .

For a new application, the virtual environment route is usually the clearest because it makes the interpreter and installed dependencies explicit. For a one-off command in a controlled environment, a direct pip install may be enough. Source installation is for working with the project source rather than ordinary package consumption.

Three ways to make Requests available to a Python project: install a release, isolate it in a virtual environment, or work from source.
Three ways to make Requests available to a Python project: install a release, isolate it in a virtual environment, or work from source.

Platform, Python, and package-manager notes

Use the correct Python launcher

Launcher names vary. The Python Packaging User Guide demonstrates python3 on Unix-like systems and py on Windows. On a machine with multiple Python installations, the plain python command may refer to a different interpreter than expected. Bind installation and execution to the same interpreter:

python -m pip install requests
python your_script.py

Or, if you use python3 to run the script, install with python3 -m pip. Likewise, pair py -m pip with the matching Windows launcher invocation.

Check version compatibility in context

Compatibility statements depend on which Requests release or documentation line is being discussed. The PyPI metadata for Requests 2.32.5 lists Python 3.9–3.14 classifiers and PyPy. The latest Requests documentation says its current documentation line officially supports Python 3.10 and newer. These are different contexts: classifiers attached to a specific published release are not the same claim as the current documentation’s support statement. Consult the metadata and documentation for the release you plan to use. Requests 2.32.5 on PyPI · Latest Requests documentation.

Update pip only if needed

If pip reports that it is too old to install a package or resolve its metadata, update pip in the target environment:

python -m pip install --upgrade pip

Then retry the Requests installation. In a virtual environment, this updates that environment’s pip. Avoid using a bare pip command if you are uncertain which Python it belongs to.

Offline, private index, and local package installs

If the machine cannot reach the public package index, pip can install from files already available locally. A wheel is a built package archive; a source archive may need build steps. The package and its dependencies must be available in the offline directory for a fully offline installation.

python -m pip install --no-index --find-links=/path/to/wheels requests

You can also install a specific local wheel or source archive by giving pip its path:

python -m pip install /path/to/requests-2.32.5-py3-none-any.whl

For an organization’s package index, pip supports selecting an index with --index-url and adding an additional index with --extra-index-url. Follow your organization’s package configuration and trust policy; index settings affect where pip looks for packages.

python -m pip install --index-url https://packages.example.invalid/simple requests

The example host above is deliberately a placeholder, not a real package service. Replace it with the URL supplied by your administrator. For private indexes, authentication and certificates may also need configuration. Avoid putting credentials directly in shell history or shared scripts.

Troubleshooting installation problems

Symptom Likely cause What to do
pip: command not found or pip is missing The shell cannot find a standalone pip command, or pip is absent for that interpreter. Try python -m pip, python3 -m pip, or py -m pip. If pip is missing, use Python’s ensurepip where available or follow the Python installation guidance for that system.
ModuleNotFoundError: No module named 'requests' Requests was installed for a different Python, or the environment used to run the script is not active. Run python -m pip show requests and python -c "import sys; print(sys.executable)" with the same launcher used for the script. Install through that interpreter.
externally-managed-environment The operating system protects its managed Python installation from pip changes. Create a project virtual environment with python -m venv .venv, activate it, and install there. This avoids changing the OS-managed interpreter.
Permission denied during install You are trying to write to a system or shared Python location without permission. Use a virtual environment. Avoid escalating privileges or using system-wide pip unless you are administering that Python installation and understand its package policy.
No matching distribution found The configured index may not contain the package, the network or index setting may be wrong, or the interpreter may not satisfy available package metadata. Check the Python version, index URL, spelling, and network access. If using a private index, verify that it mirrors Requests and its dependencies.
TLS or certificate verification error A proxy, custom certificate authority, incorrect system clock, or TLS inspection may interfere with pip’s secure connection. Check the system clock and network’s approved certificate configuration. For a managed network, ask the administrator for the trusted CA setup rather than disabling certificate checks.
Install succeeds but IDE import fails The IDE selected a different interpreter from the terminal. Set the IDE’s project interpreter to the environment where Requests was installed, then restart its Python process if necessary.
Source install fails after cloning The checkout may be incomplete, the selected Python/pip may be wrong, or build requirements may be unavailable. Run the command from the repository root, confirm the active interpreter, update pip in the environment if pip requests it, and inspect the first build error for missing tools or unavailable dependencies.

When diagnosing, collect the interpreter path and pip’s view of the package rather than guessing:

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

Those commands reveal which Python is active, which interpreter owns pip, and whether that interpreter can see the package.

Performance, reliability, and cost considerations

Installing Requests is a one-time environment setup step; it does not make subsequent HTTP requests faster by itself. Runtime latency depends on the network, destination server, response size, and how the application handles connections. For reliability, specify a timeout on network calls and handle exceptions appropriate to your application. Do not confuse a successful package installation with a guarantee that a later URL is reachable.

Virtual environments add little operational complexity and make dependency placement predictable. For repeatable deployments, retain a dependency file and provision it during build or setup. Offline installs require you to prepare compatible package files, including dependencies, ahead of time. Package downloads and source builds also consume network and machine resources; pip does not charge a fee for the Requests package itself, though your network or compute provider may have its own costs.

Or skip the browser setup

Requests is for making HTTP requests from Python; it does not render a page like a browser. If your goal is a website screenshot, a screenshot API can capture the rendered page without setting up browser automation. ScreenshotNeo is a website screenshot API and MCP server. Here is a one-call example using Python Requests after installing the library as above. See the ScreenshotNeo API documentation for request details.

import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
    timeout=90,
)
open("shot.webp", "wb").write(r.content)

ScreenshotNeo accepts cookie and consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers identify the page verdict and billing status. Its MCP server gives AI agents tools to take screenshots, get page information, and capture PDFs. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots.

Sign up free for 1,000 screenshots a month, no card required.

FAQ

Is Requests part of Python’s standard library?

No. Requests is an installable third-party package, so install it in the Python environment that runs your code.

A screenshot API handles browser rendering and removes common page overlays before returning the image.
A screenshot API handles browser rendering and removes common page overlays before returning the image.

Can I use Requests without activating a virtual environment?

Yes. You can call the environment’s Python executable directly. Activation is a shell convenience; using the intended interpreter is what matters.

Do I need Git to install Requests?

No. Git is needed for the repository-clone source route. The usual PyPI installation uses pip and does not require you to clone the project.

Why does my program install successfully but still fail to import Requests?

The installer and program are likely using different Python interpreters. Compare their executable paths and use the same interpreter for pip and script execution.