'No module named requests' even if I installed requests with pip

Viewed 36847

I'm trying to test if requests module has been well installed. But I'm getting the following error :

raceback (most recent call last):
  File "/Users/macbookpro/Desktop/test.py", line 1, in <module>
    import requests
ImportError: No module named requests

when trying to run the following test script:

import requests
print 'test'

But I have installed requests with pip, and pip list command gives the following result :

MBPdeMacBook2:~ macbookpro$ pip list
arrow (0.7.0)
beautifulsoup4 (4.4.1)
classifier (1.6.5)
coursera-dl (0.6.1)
Django (1.8.6)
html5lib (1.0b8)
keyring (9.0)
lxml (3.6.0)
Pillow (3.4.2)
pip (8.0.2)
pyasn1 (0.1.9)
requests (2.14.2)
setuptools (19.4)
six (1.10.0)
urllib3 (1.16)
vboxapi (1.0)
virtualenv (13.1.2)
wheel (0.26.0)

Why requests isn't being imported ?

EDIT :

MBPdeMacBook2:~ macbookpro$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
MBPdeMacBook2:~ macbookpro$ which pip
/usr/local/bin/pip
MBPdeMacBook2:~ macbookpro$ python --version
Python 2.7.11
MBPdeMacBook2:~ macbookpro$ pip --version
pip 8.0.2 from /usr/local/lib/python2.7/site-packages (python 2.7)
5 Answers

I experienced this same issue on Ubuntu 18.04 LTS, to check that, I first checked if requests library was installed on my system or not.

Run these commands on your terminal inside the virtual environment in which you working

$ python

Then the python command line opens, then run

>>> import requests

After this if you get an ImportError saying, No module named requests, then it means the dependency has not been installed properly. If there is no such error, then it means the dependency is installed successfully.

This can occur for example if pip is actually pip3 and python is actually python2.7. In your case the which pip and which python eliminate this possibility but it just happened to me.

The solution was to do pip2 instead of pip; if the situation was reversed you can use pip3.

Related