Tools and workflows

How to install Requests with pip in Python

Install Requests with python -m pip, verify the package location, and diagnose ModuleNotFoundError when pip and your editor use different interpreters.

Run python -m pip install requests with the same interpreter that will run the script. Use python3 if that is your command for Python. Then run python -m pip show requests with that same executable. If installation succeeds but the import fails, compare the interpreter paths before installing the package again.

Install into the project's virtual environment

If the project already declares dependencies, follow its install instructions. It might require a specific release range or use a lock file. For a new disposable practice folder, create .venv with python -m venv .venv or python3 -m venv .venv. Use one of these commands for the new environment from the project folder.

.\.venv\Scripts\python.exe -m pip install requests
.\.venv\Scripts\python.exe -m pip show requests
./.venv/bin/python -m pip install requests
./.venv/bin/python -m pip show requests

The second command displays the installed distribution metadata and location. It does not contact an API. If the project uses a company package mirror, use its documented configuration. Do not install an unfamiliar package just because it has a similar name.

Confirm what an import resolves

From the same folder in which you run your project, execute python -c "import requests; print(requests.__file__)", substituting the environment executable when needed. The resulting path should point into the environment's package directory. If instead it points to your own requests.py, rename that file. The local module name can shadow the installed library. Do the same if you gave a local folder the import name.

If an editor can import Requests but a scheduled run cannot, compare sys.executable and the working directory in both runs. A fresh editor terminal may activate the expected environment. A scheduled Python task can name that executable by its full path.

Interpret the other common errors

A failure to obtain the package may come from connectivity, certificate configuration, repository permissions, or a Python version unsupported by the available release. Read the install error before repeating it. Use the trusted certificate configuration and repository settings for your device. Granting administrator privileges or disabling certificate checks changes the problem and can create new risks.

An externally managed environment notice often means the distribution expects system packages to stay under its package manager's control. Make a virtual environment for the project and install there. On some systems, the operating system must first provide its venv support package. If this is a managed machine, check the installation method available under your account.

Recognize a dependency problem that is not an install failure

A successful installation can still be followed by an error from one of Requests' dependencies. Capture the first traceback and identify which file Python imported. Running pip's check command can reveal incompatible declared requirements, but it cannot diagnose every runtime problem. A newer dependency version can satisfy a declaration while still affecting a program that assumed undocumented behavior.

When a team's setup suddenly changes, compare the resolved package versions with a known working environment. Avoid upgrading all dependencies at once as a first diagnostic. Reproduce the failure using a clean environment and the project's own dependency specification, then make one bounded change and retry the same sample.

Check the three paths in a real example

Imagine you created an environment under project-a and installed Requests. A terminal opened under project-b echoes Successfully installed during another install command, yet the editor cannot import it. Compare the interpreter path printed by the editor, the location displayed by that interpreter's pip show requests, and the path printed by requests.__file__ when the import succeeds. Version numbers alone cannot confirm all three refer to the same copy.

A missing pip show record usually means you need to review that environment's installation. A present record and an import from the project directory suggest shadowing. A record and an import from different virtual environments can expose an unintended search-path change. Treat those paths as observations before making a corrective edit.

Leave a reproducible result

List Requests as a dependency if the program imports it. After installing the dependencies, python -m pip check reports missing or incompatible declared requirements in that environment. It does not exercise your program. Run a small local test or known sample afterward.

Write down which environment, interpreter version, and dependency specification worked. Then try the setup in a new environment. This is the point at which you can tell whether the project depends on a stable setup or on extra packages left behind by earlier experiments.

Sources and further reading

Related reading

Browse Tools and workflows · Explore project tutorials

Search PythonProjects.org