问题描述
我正在使用 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.
失败的尝试
信息
- 从
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\
:安全。
-
注意:此处和下面的所有测试都是使用 env\Scripts\python
和 env\Scripts\pip
从 AutoMate\ 运行的。
-
没有在 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
** 的any文件。
任何*其他文件名都有效,甚至 calendar.python
和 Calendar.py
。
** 在测试中似乎 requests.py
和 datetime.py
也是一些无效名称,而 math.py
和 time.py
似乎工作正常,也许使用了无效名称内部?需要进一步了解。
原因
看起来有些人对我有一些内部干扰,我希望有人也能回答这个问题的原因。