Python“请求”安装问题 - HTTPBasicAuth

Jee*_*eef 0 python python-2.7 python-requests

我在 mac 上并尝试了以下操作:

easy_install requests

pip install requests

当我import requests在 REPL 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.
>>> import requests
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "requests.py", line 4, in <module>
    from requests.auth import HTTPBasicAuth
ImportError: No module named auth
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

Mar*_*ers 5

requests.py在当前目录中有一个本地模块。重命名该文件,它掩盖了已安装的库。

您的回溯中发生了什么:

  1. Python 尝试查找requests并且sys.path搜索路径上的第一项是名为 的文件requests.py,它符合要求。
  2. 该文件包含行from requests.auth import HTTPBasicAuth,Python 尝试导入该行。
  3. Python 已经requests导入了一个模块(从第 1 步开始),但由于它是一个普通模块而不是包,因此ImportError会抛出an 。