Google API发生故障-ImportError:无法导入名称“ build”

时间:2019-05-17 20:30:57

标签: python google-calendar-api google-api-python-client

起初,我希望我可以在Internet上的任何地方找到此问题,但是我搜索了一段时间却找不到任何存在类似问题的人。当我尝试运行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,我对此跟踪感到非常困惑,因为它似乎在我的代码中引用了两个不同的行。

我在做什么错了?

1 个答案:

答案 0 :(得分:1)

您已引起循环进口。您的文件称为calendar.py,它将隐藏相同名称的标准库模块。正如您在回溯中看到的那样,_parseaddr.py导入了calendar,期望找到stdlib模块,但是找到了您的stdlib模块,现在它处于一个圆圈中。

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