Reputation: 311
Trying to import 'requests'
.
Has it installed via pip3
install requests? But still, have this error.
C:\Users\Vikentiy>pip3 list
Package Version
---------- ----------
certifi 2018.11.29
chardet 3.0.4
Django 2.1.7
idna 2.8
pip 19.0.2
pytz 2018.9
requests 2.21.0
setuptools 40.6.2
simplejson 3.16.0
urllib3 1.24.1
virtualenv 16.4.0
C:\Users\Vikentiy>python --version
Python 3.7.2
Error Traceback:
C:\Users\Vikentiy\untitled2\venv\Scripts\python.exe C:/Users/Vikentiy/untitled2/requeststests.py
Traceback (most recent call last):
File "C:/Users/Vikentiy/untitled2/requeststests.py", line 1, in <module> import requests`
Upvotes: 21
Views: 132384
Reputation: 19
Actually You are using an IDE like VS Code. In case of VS Code change the "Default Interpreter Path". There error happens that there is another python version installed on your system and your IDE is using that version. Now what to do: Steps:
Upvotes: 0
Reputation: 797
There is a possibility that you are having more than one Python installations and you have this module installed in one installation but using another for execution.
You can check the Python interpreter you are using for execution.
Run
pip show <module name>
and check the module causing issue, is in which location, this will tell you which Python installation you should use as your interpreter or else you can copy the module files manually to your current Python interpreter installation's location.
Upvotes: 0
Reputation: 44
requests could be many different sub-modules so like if you are using urllib request it would be
import urllib.request
I would recommend urllib.request because it has worked well in the past. I'm pretty sure "requests" is pretty old and very finicky and difficult to use. i was trying to access data from a server a few days ago so users wouldn't have to redownload in order to get updates and instead run code grabbed from my webserver. I tried getting requests to work but to no avail. after some digging around I found urllib which worked like a charm.
for example, this code grabs code from a webpage and executes it:
import urllib.request
page = urllib.request.urlopen('https://pastebin.com/raw/j5LSmvP4')
r = page.read()
exec(r.decode())
also when creating a StackOverflow question, I would recommend showing a code snippet or example as a visual representation to know what the answer-er is dealing with in terms of context.
Upvotes: 0
Reputation: 89
If you are using venv (virtual environment), you may need to consider where it's path. for my case it was outside my project folder. So I had to first install request inside the main python's path then I recreate venv inside my project.
inside_your_project#python -m venv ./venv
Upvotes: 1
Reputation: 6520
This issue is due to missing request module in python package .So you can use below command to install and recheck by restarting your IDE
pip install requests
If already installed better to upgrade
pip install --upgrade pip
Upvotes: 1
Reputation: 336
Try to uninstall requests and then again install it using pip
pip uninstall requests
and again install it
pip install requests
or if you didn't get what I am saying so please visit
Upvotes: 9
Reputation: 519
That's the exact solution which works for me, please follow this:
As like, first try to get the version of the requests
module installed previously, this can be find by
pip install requests
Now, you will get the message:
Requirement already satisfied: requests in /opt/anaconda3/lib/python3.8/site-packages (2.24.0)
See, here the version of the requests module i.e., (2.24.0)
Now, the simple basic logic is this like you should install just the previous version of the requests (2.24.0)
. So, you should now install requests (2.20.0)
For this use command:
pip install requests==2.20.0
Now, I think you can test import requests
and this will work fine.
Further, if any error occurs then please let me know in the comments.
Thanks, HaPpY Coding 🤗
Upvotes: 2
Reputation: 883
Another cause of this might be multiple Python versions installations. So if you type in your terminal:
pip3 install requests
The requests library will be automatically installed to your default python3, for example, Python3.6. However, let's say you have another Python version, for example, Python3.7, what you should do is:
pip3.7 install requests
This should solve this problem.
If you are running your code in the terminal, you should try:
python3.7 file_to_run.py
Upvotes: 12
Reputation: 65692
If it is installed this will WORK:
c:\>python (or on Mac/Linux "$ python")
>>> import requests
>>> requests.get("http://127.0.0.1")
<Response [200]>
If you see this error when running your script/IDE:
Traceback (most recent call last): File "E:\test.py", line 1, in <module>
import requests
ImportError: No module named requests
Try:
python script.py
Answer is based on https://www.edureka.co/community/84584/python-requests-module-import-error-module-named-requests
Then the trick for me was not to start up a VirtualEnv, I actually found I was running the x64 version of python when I'd installed the requests package into the python 32 bit folder c:\program files (x86)\python37-32\lib\site-packages. This is a screenshot from the internet but it shows you how to change the interpreter you're using - in my case - I need to set it to Python 3.7.4(x86) 32 bit:
Upvotes: 3
Reputation: 21
Run in command prompt
and write command pip install requests
in scripts directory
cd \Python27\scripts
pip install requests
Upvotes: 2
Reputation: 417
If you're using PyCharm as IDE, try closing and restarting PyCharm. Move the mouse cursor over the "requests" (with red curly line beneath it), until the red light bulb next to it show up. Select the first option in it, "Install package requests". PyCharm will take care of the installation from there.
I ran into the same issue and have tried all the solutions here on Stack Overflow.
Upvotes: 4