python - 为什么没有根据 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.
失败的尝试
- 删除并重新制作 venv。
- 使用 --no-cache-dir 和 --ignore-installed 安装模块。
信息
- 从作品中执行
import requests
或from google.auth.transport.requests import Request
从控制台执行env\Scripts\python
没有问题。 - 放置在以下目录中的文件中的相同行
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
。
在 venv 之外的 pip 中没有安装任何 google auth 模块。
项目结构如下:
AutoMate
| temp.py
├───env
│ ├───Include
│ ├───Lib
│ └───Scripts
└───src
│ AutoMate.pyw
│
└───sources
│ calendar.py --> Problematic file
│ whatsapp.py
│ __init__.py
│
└───util
- 输出
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
解决方案
解决方案
任何使用的文件google.auth.transport.requests
都不得在与其自身相同的目录中包含任何完全命名为 ** 的文件。calendar.py
任何* 其他文件名都有效,甚至calendar.python
和Calendar.py
.
** 在测试中,它似乎requests.py
也是datetime.py
一些无效名称,而math.py
似乎time.py
工作正常,也许无效名称是在内部使用的?需要进一步了解。
原因
看起来有些人对我有一些内部干扰,我希望有人也能回答这个问题的原因。
推荐阅读
- outlook - Outlook MailItem 正文有时变得不可读
- javascript - 如何通过 id().innerText 打破元素的循环未定义
- html - 在 react / html 中渲染新行 (\n)
- c++ - C++向量排序程序
- r - 按字母顺序对具有相同条目的多个列进行排序
- node.js - 树莓派 QR 扫描仪 CPU 使用率高
- spring-data-elasticsearch - Spring-data-elasticsearch @CompletionField 不创建映射类型 Completion
- flutter - 没有这样的方法错误。getter 在 null 上被调用
- javascript - 未捕获的 TypeError:分配给 javascript 模块中的常量变量
- python - Docker 容器网络:Redis 和自定义镜像