pythonpython-2.7python-requests

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


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)

Solution

  • I am not 100% sure, but the paths from which python and which pip may indicate that you have two versions installed. The Python version being the old one that was shipped with OS X, and another version.

    I would advice you to install Python27 (or even better Python3) from brew.

    You can install brew with a single command, and another one for installing Python27/3. When this is done you set the PATH variable in your shell rc file and you should be good to go.

    I have Python27 installed (via brew) and my (working environment) reports the following paths:

    which python: /usr/local/bin/python
    which pip: /usr/local/bin/pip
    

    And

    python --version: 2.7.15
    pip --version: pip 9.0.1 from /usr/local/lib/python2.7/site-packages (python2.7)