【问题标题】:How to troubleshoot an allegedly missing module (google.oauth2)?如何对据称丢失的模块 (google.oauth2) 进行故障排除?
【发布时间】:2020-05-16 04:28:04
【问题描述】:

我想试验一下connecting to Google Calendar APIs with a service account

示例代码需要google.oauth2,由于某种原因我无法导入:

C:\Users\yop>pip3 install google
Requirement already satisfied: google in c:\users\yop\appdata\local\programs\python\python37-32\lib\site-packages (2.0.3)
Requirement already satisfied: beautifulsoup4 in c:\users\yop\appdata\local\programs\python\python37-32\lib\site-packages (from google) (4.8.2)
Requirement already satisfied: soupsieve>=1.2 in c:\users\yop\appdata\local\programs\python\python37-32\lib\site-packages (from beautifulsoup4->google) (1.9.5)

C:\Users\yop>python
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import google
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'google'

我该如何解决这个问题?该模块似乎已安装,适用于正确的 Python 版本。

相比之下,考虑arrow模块,安装方式相同:

C:\Users\yop>pip3 install arrow
Requirement already satisfied: arrow in c:\users\yop\appdata\local\programs\python\python37-32\lib\site-packages (0.11.0)
Requirement already satisfied: python-dateutil in c:\users\yop\appdata\local\programs\python\python37-32\lib\site-packages (from arrow) (2.8.0)
Requirement already satisfied: six>=1.5 in c:\users\yop\appdata\local\programs\python\python37-32\lib\site-packages (from python-dateutil->arrow) (1.12.0)

C:\Users\yop>python
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import arrow
>>> arrow.__file__
'C:\\Users\\yop\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages\\arrow\\__init__.py'

【问题讨论】:

  • @AlirezaTajadod: 是的,同样的错误。但是你指出了我正确的方向,要安装的模块不同(github.com/googleapis/google-api-python-client/blob/master/docs/…)→ 你介意把它变成一个答案(我安装了两个模块都可以正常工作)
  • 也许您可以尝试使用正确的解释器安装模块:python -m pip install google
  • 正如@AlirezaTajadod 指出的那样,这是错误的模块。如果您需要使用google.oauth2pip3 install google-auth-oauthlib 可以工作@
  • @Axe319:是的,我修改了他们的答案以包含所有链接

标签: python python-3.x python-import python-module


【解决方案1】:

为了import google要安装的模块是google-auth and google-auth-oauthlib

pip3 install google-auth google-auth-oauthlib

之后你就可以import google.oauth2

【讨论】:

  • 感谢您的提示 - 我以某种方式重写了您的答案,以明确指出文档、要导入的内容等。
猜你喜欢
  • 2012-04-25
  • 2011-02-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多