在python中导入请求模块在OS X上不起作用

时间:2016-03-23 14:35:33

标签: python macos python-2.7 python-requests

我的系统上安装了请求模块。

pip install requests

现在我正在尝试在rpel中导入请求

import requests

失败并出现以下错误

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named requests

我找到了这个问题here的答案,但它没有说明在同一目录中使用python 2.x.

我的终端出局是:

MacBook-Pro:~ tanmaybaranwal$ which python

/usr/bin/python

MacBook-Pro:~ tanmaybaranwal$ which python2.6

/usr/bin/python2.6

MacBook-Pro:~ tanmaybaranwal$ which pip

/usr/local/bin/pip

MacBook-Pro:~ tanmaybaranwal$ sudo pip install python-firebase
Password:
Requirement already satisfied (use --upgrade to upgrade): python-firebase in /Library/Python/2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): requests>=1.1.0 in ./Library/Python/2.7/lib/python/site-packages (from python-firebase)
Cleaning up...

MacBook-Pro:~ tanmaybaranwal$ sudo pip install requests
Requirement already satisfied (use --upgrade to upgrade): requests in ./Library/Python/2.7/lib/python/site-packages
Cleaning up...

MacBook-Pro:~ tanmaybaranwal$ python
Python 2.7.10 (default, Oct 23 2015, 18:05:06) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> import firebase
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/firebase/__init__.py", line 4, in <module>
    from firebase import *
  File "/Library/Python/2.7/site-packages/firebase/firebase.py", line 10, in <module>
    from .decorators import http_connection
  File "/Library/Python/2.7/site-packages/firebase/decorators.py", line 1, in <module>
    import requests
ImportError: No module named requests

列出PIP模块也没有任何requests模块。

1 个答案:

答案 0 :(得分:4)

为了确保您使用正确的python来安装带有pip的内容,您可以通过-m

运行它
$ python -m pip install --user requests

(如果省略--user标志,则可能需要root权限)