gpt4 book ai didi

python - Google API 出现故障 - ImportError : cannot import name 'build'

转载 作者:行者123 更新时间:2023-12-02 08:10:52 26 4
gpt4 key购买 nike

起初,我希望能在互联网上的任何地方找到这个问题,但我搜索了一段时间,找不到任何人有类似的问题。当我尝试运行 googleapiclient 模块时,它在某个地方失败了 - 而且我不确定出了什么问题。为了测试它,我开始运行以下文件:

import googleapiclient
print('Step one!')
import googleapiclient.discovery
print('Step two!')
from googleapiclient.discovery import build
print('Yay! All steps complete!')

第一次导入进展顺利,因为第一个打印语句已成功生成。然而,在那之后,一切似乎都出了问题;

Step one!
Traceback (most recent call last):
File "c:/Users/Bram/Documents/My Project/src/test.py", line 3, in <module>
import googleapiclient.discovery
File "C:\Users\Bram\AppData\Local\Programs\Python\Python36-32\lib\site-packages\googleapiclient\discovery.py", line 32, in <module>
from six.moves import http_client
File "C:\Users\Bram\AppData\Local\Programs\Python\Python36-32\lib\site-packages\six.py", line 92, in __get__
result = self._resolve()
File "C:\Users\Bram\AppData\Local\Programs\Python\Python36-32\lib\site-packages\six.py", line 115, in _resolve
return _import_module(self.mod)
File "C:\Users\Bram\AppData\Local\Programs\Python\Python36-32\lib\site-packages\six.py", line 82, in _import_module
__import__(name)
File "C:\Users\Bram\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 71, in <module>
import email.parser
File "C:\Users\Bram\AppData\Local\Programs\Python\Python36-32\lib\email\parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "C:\Users\Bram\AppData\Local\Programs\Python\Python36-32\lib\email\feedparser.py", line 27, in <module>
from email._policybase import compat32
File "C:\Users\Bram\AppData\Local\Programs\Python\Python36-32\lib\email\_policybase.py", line 9, in <module>
from email.utils import _has_surrogates
File "C:\Users\Bram\AppData\Local\Programs\Python\Python36-32\lib\email\utils.py", line 33, in <module>
from email._parseaddr import quote
File "C:\Users\Bram\AppData\Local\Programs\Python\Python36-32\lib\email\_parseaddr.py", line 16, in <module>
import time, calendar
File "c:\Users\Bram\Documents\My Project\src\calendar.py", line 5, in <module>
from googleapiclient.discovery import build
ImportError: cannot import name 'build'

我尝试使用 pip 强制重新安装模块。我已经安装了人们在类似线程上建议的任何软件包,但人们在使用该软件包时遇到了问题,(谈论 apiclienthttplib2oauth2clienturitemplate),我对这个 Traceback 感到非常困惑,因为它似乎引用了我的代码中的两行不同的行。

我做错了什么?

最佳答案

您造成了循环导入。您的文件名为 calendar.py,它隐藏了同名的标准库模块。正如您在回溯中看到的,_parseaddr.py 导入 calendar,希望找到 stdlib 模块,但却找到了您的模块,并且现在处于一个圆圈中。

将文件重命名为其他名称。

关于python - Google API 出现故障 - ImportError : cannot import name 'build' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56193186/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com