【问题标题】:Python "Requests" install issue - HTTPBasicAuthPython“请求”安装问题 - HTTPBasicAuth
【发布时间】:2014-09-30 10:23:21
【问题描述】:

我在 Mac 上并尝试了以下方法:

easy_install requests

pip install requests

当我在 REPL python 中尝试import requests 命令时,出现以下错误

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

我做错了什么?

【问题讨论】:

    标签: python python-2.7 python-requests


    【解决方案1】:

    您的当前目录中有一个名为requests.py 的本地模块。重命名该文件,它会屏蔽已安装的库。

    您的回溯中发生了什么:

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

    【讨论】:

      猜你喜欢
      • 2012-02-20
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 2013-01-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多