アレックス アレックス - 4 months ago 20
Python Question

Can't import requests_oauthlib

I've failed to import

requests_oauthlib
, although I've installed it successfully:

$ sudo pip install requests requests_oauthlib
Requirement already satisfied (use --upgrade to upgrade): requests in /Library/Python/2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): requests-oauthlib in /usr/local/lib/python2.7/site-packages
Cleaning up...
~ alex$ python
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from requests_oauthlib import OAuth1Session
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named requests_oauthlib


update:

>>> import sys; print sys.path
['', '/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', '/Library/Python/2.7/site-packages']

Answer

requests-oauthlib is installed at /usr/local/lib/python2.7/site-packages.

But the latter is not in your PYTHONPATH/sys.path

So add it. This is one way.

sys.path.append('/usr/local/lib/python2.7/site-packages/')

Learn about pythonpath

Comments