Reputation: 67
I simply wrote the following code to play around with the Requests library
requests tests
import requests
r = requests.get('https://api.github.com/events')
but I keep getting the same error message, even if I use from requests import *
Traceback (most recent call last):
File "/Users/dvanderknaap/Desktop/Organized/CS/My_Python_Programs/requests.py", line 3, in <module>
import requests
File "/Users/dvanderknaap/Desktop/Organized/CS/My_Python_Programs/requests.py", line 5, in <module>
r = requests.get('https://api.github.com/events')
AttributeError: 'module' object has no attribute 'get'
I've tried reinstalling requests using pip install requests
, but the output is:
Requirement already satisfied (use --upgrade to upgrade): requests in /anaconda/lib/python3.5/site-packages
I think the problem is that it is installed in my python3.5 library but I am using python2.7, but I'm not sure how to fix that. Advice?
Upvotes: 5
Views: 18509
Reputation: 133929
Instead of expecting that there is a proper wrapper for your pip
with a version number, use the pip
module of your desired Python interpreter:
% python2.7 -mpip install requests
Upvotes: 0
Reputation: 544
First, rename your file My_Python_Programs/requests.py to something else than requests.py. It is importing itself instead of the requests module.
Your python 2.7 may or may not already have the requests package installed. If not, you can install it with
pip2.7 install requests
Upvotes: 8