无法导入requests_oauthlib

时间:2014-11-17 04:38:56

标签: python macos oauth

我已经无法导入requests_oauthlib,虽然我已经成功安装了它:

$ 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

更新

>>> 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']

2 个答案:

答案 0 :(得分:14)

我有这个问题,除了确保设置了正确的路径之外,我发现正在运行 $ pip install requests requests_oauthlib 解决了这个问题,因为oauthlib不包含在核心requests库中。

https://github.com/requests/requests-oauthlib

答案 1 :(得分:2)

requests-oauthlib已安装在/usr/local/lib/python2.7/site-packages

但后者不在您的PYTHONPATH / sys.path

所以添加它。这是一种方式。

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

Learn about pythonpath