我正在使用 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