13

I have installed the pip3 as well as the requests package on my pc. Even then, on running the command import requests on my shell, I am getting the following error:

Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import requests
ModuleNotFoundError: No module named 'requests'

I have to manually copy all the packages to my working directory to tackle this exception.

I am working with Windows 10, using a Python 3.6.1 shell.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jaskunwar singh
  • 205
  • 3
  • 5
  • 10

7 Answers7

17

Find were your Python interpreter is installed and find the "Scripts" directory. Open cmd, go to this folder and type pip install requests.

For me it was like below:

cd C:\Users\myLocalUserName\AppData\Local\Programs\Python\Python36\Scripts
pip install requests
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Hawlett
  • 836
  • 16
  • 23
2

In PyCharm you should:

  1. Go back to base configuration in menu "File""Settings""Python Interpreter" (it is the path that ends with "...\python.exe")
  2. Click on the plus and install this module by typing name in search field.
  3. Choose this configuration and run it by pressing Ctrl + Alt + F10
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
2

For listing installed modules for Python 3:

sudo pip3 list

For installing the request module for Python 3:

sudo pip3 install requests
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
simhumileco
  • 31,877
  • 16
  • 137
  • 115
1

Make sure that Requests module should have a version that starts with 2.

Not correct

pip3 list

Output:

Package         Version
--------------- -------
requestes       0.0.1

I installed this and installed using

python -m pip install requests

Later:

cd C:\python\Scripts
pip list

Output:

Package         Version
--------------- ---------

certifi         2021.5.30

chardet         4.0.0

idna            2.10

pip             21.1.3

**requests        2.25.1**

urllib3         1.26.6
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
sterin jacob
  • 141
  • 1
  • 10
  • *requestes* vs. *requests*: Are you sure it is not some kind of [typosquatting](https://en.wikipedia.org/wiki/Typosquatting)? – Peter Mortensen Jul 02 '23 at 16:34
  • [See](https://stackoverflow.com/questions/76440240/getting-this-error-while-installing-the-request-module-of-python?noredirect=1&lq=1#comment134785674_76440240) e.g. *[Several malicious typosquatted Python libraries found on PyPI repository](https://thehackernews.com/2021/07/several-malicious-typosquatted-python.html)*. That is, '`requests`' (the real library) vs. '`request`' (The malicious one. Without "s") – Peter Mortensen Jul 02 '23 at 16:54
0

Activate a virtual environment:

.\env\Scripts\activate

Install the dependencies:

pip install request
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
0

I have been tackling this issue for two hours now, and this solution did it!

Find your Python installation location and, specifically, the Scripts directory. Open cmd, and run the following:

cd C:\Users\<myLocalUserName>\AppData\Local\Programs\Python\Python36\Scripts
pip install requests
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Se7en Axis
  • 59
  • 5
0

For me, I used the package manager within my IDE (PyCharm in this case) to see if 'request' was installed. Once I did that, then the error went away.

I also tried pip install, but I suspect I have multiple Python installations on the system and pip didn't install to the correct Python interpreter. This is why others are suggesting to install from a specific Python installation.

In Linux or Mac, you can run 'which python' for additional clues.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • Re *"request"* (without "`s`"): That is probably why [the typosquatting attack](https://stackoverflow.com/questions/76440240/getting-this-error-while-installing-the-request-module-of-python?noredirect=1&lq=1#comment134785674_76440240) was so successful. – Peter Mortensen Jul 02 '23 at 17:06