首页 > 解决方案 > 安装 google api 客户端以从 python 发送电子邮件

问题描述

我正在尝试学习如何使用 Gmail API 在 python 中发送电子邮件。

我脚本的第一行之一:

from googleapiclient.discovery import build

给我错误:

No module named googleapiclient.discovery

我正在尝试通过执行以下操作来安装 googleapiclient:

sudo pip install --upgrade google-api-python-client

这似乎做所有正确的事情,直到它说:

Installing collected packages: httplib2, uritemplate, rsa, cachetools, pyasn1-modules, google-auth, google-auth-httplib2, google-api-python-client
  Found existing installation: httplib2 0.9.1
Cannot uninstall 'httplib2'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

我不确定这条消息是否会停止工作,但我仍然收到消息:

No module named googleapiclient.discovery

当我尝试运行我的代码时。任何建议都感激不尽!

标签: pythongmail-api

解决方案


OP 面临着这里提到的类似问题。

在大多数情况下,使用--user安装包的选项可以解决这个问题。在安装软件包之前。我们必须先卸载google-api-python-client

pip uninstall google-api-python-client

现在install使用该--user选项的包。

pip install --user google-api-python-client

推荐阅读