首页 > 解决方案 > 为什么没有根据 google-auth 库安装 requests 模块?

问题描述

我正在使用 Google Calendar API 来获取一些事件,并且我正在使用 venv 来容纳所有需要的包,我遇到了一个简单的问题:google.auth.transport.requests无法正常运行,因为requests没有安装包。

代码和错误:


可以使用一行代码观察到该问题:

from google.auth.transport.requests import Request

以下错误从google.auth.transport.requests(在两个回溯的底部)转储到控制台:

File "<string>", line 3, in raise_from
ImportError: The requests library is not installed, please install the requests package to use the requests transport.

失败的尝试


  1. 删除并重新制作 venv。
  2. 使用 --no-cache-dir 和 --ignore-installed 安装模块。

信息


  1. 从作品中执行import requestsfrom google.auth.transport.requests import Request从控制台执行env\Scripts\python没有问题。
  2. 放置在以下目录中的文件中的相同行temp.py以下列方式执行:
    • AutoMate\: 安全的
    • AutoMate\src\: 安全的
    • AutoMate\src\sources\: 错误
    • AutoMate\src\sources\temp\:安全(sources\temp 仅用于调试)
    • AutoMate\src\sources\util\: 安全的。

注意:这里和下面的所有测试都是从 AutoMate\ 使用env\Scripts\python和运行的env\Scripts\pip

  1. 在 venv 之外的 pip 中没有安装任何 google auth 模块。

  2. 项目结构如下:

AutoMate
|   temp.py
├───env
│   ├───Include
│   ├───Lib
│   └───Scripts
└───src
    │   AutoMate.pyw
    │
    └───sources
        │   calendar.py --> Problematic file
        │   whatsapp.py
        │   __init__.py
        │  
        └───util

  1. 输出env\Scripts\pip list
Package                  Version
------------------------ ---------
cachetools               4.2.1
certifi                  2020.12.5
chardet                  4.0.0
google-api-core          1.26.1
google-api-python-client 2.0.2
google-auth              1.27.1
google-auth-httplib2     0.1.0
google-auth-oauthlib     0.4.3
googleapis-common-protos 1.53.0
httplib2                 0.19.0
idna                     2.10
oauthlib                 3.1.0
packaging                20.9
pip                      21.0.1
protobuf                 3.15.5
pyasn1                   0.4.8
pyasn1-modules           0.2.8
pyparsing                2.4.7
pytz                     2021.1
requests                 2.25.1
requests-oauthlib        1.3.0
rsa                      4.7.2
selenium                 3.141.0
setuptools               49.2.1
six                      1.15.0
uritemplate              3.0.1
urllib3                  1.26.3

标签: pythonpython-requestsgoogle-calendar-apigoogle-auth-library

解决方案


解决方案


任何使用的文件google.auth.transport.requests都不得在与其自身相同的目录中包含任何完全命名为 ** 的文件。calendar.py任何* 其他文件名都有效,甚至calendar.pythonCalendar.py.

** 在测试中,它似乎requests.py也是datetime.py一些无效名称,而math.py似乎time.py工作正常,也许无效名称是在内部使用的?需要进一步了解。

原因


看起来有些人对我有一些内部干扰,我希望有人也能回答这个问题的原因。


推荐阅读