Pip install modules not installing

Viewed 2189

I imported the module requests within my project using:

pip install requests 

Apparently the module implementation did not work.

This is the error:

File "scraping.py", line 1, in <module>
    import requests
ImportError: No module named requests
4 Answers

Error explanation

This error basically says it can't find the requests module, which is a third party module for handling http requests. There are a few issues that could cause this, but likely it just didn't install properly when you tried to pip install requests

Solution

Depending on your OS you can call pip from your python installation directly through:

Windows

python -m pip install requests

MacOS/Linux

sudo python3 -m pip install requests

pip show <package name>

will give you information about a specific package.

Here is a link with more info on pip show:

more info on pip show from the offical pip documentation

you can also do:

pip list

in the command line to get a list of all the packages pip has installed.

Note: in WSL(Windows Subsystem for Linux) you may need to use pip.exe list and pip.exe show instead.

I had a similar problem a while ago where I installed the module with pip and got the same error. I used Pycharm IDE and had to go into settings -> project settings -> project interpreter and installed the module from there, which made it work. Might be similar in your IDE.

Run pip install requests and the make sure run python3 file.py

Related