我在尝试 Google Drive SDK 快速入门示例 (https://developers.google.com/drive/quickstart) 时收到以下错误消息。
Traceback (most recent call last):
File "quickstart.py", line 6, in <module>
from apiclient.discovery import build
File "build/bdist.macosx-10.6-intel/egg/apiclient/discovery.py", line 45, in <module>
File "build/bdist.macosx-10.6-intel/egg/apiclient/errors.py", line 26, in <module>
ImportError: cannot import name util
如教程中所述,首先在我的 Mac 终端上:
easy_install --upgrade google-api-python-client
我使用的是 Mac OS 10.7.4 python 2.7.2
最佳答案
我建议使用 pip
而不是 easy_install
。根据this answer对于类似的问题,客户端库和 oauth2client
库可能不兼容。最好使用 pip install -U google-api-python-client
(或用于 Python 3 的 pip3
)进行升级。
在您完成快速入门后,如果您想查看更长、更“真实世界”的使用 Drive API 的示例,这里是我为您制作的一些视频和博客文章:
- Listing your files in Google Drive和代码深入研究 post
- Google Drive: Uploading & Downloading Files加上“穷人的纯文本到 PDF 转换器”代码深潜 post (*)
- 将 Google 表格导出为 CSV 博客 post只有
(*) - TL;DR:将纯文本文件上传到云端硬盘,导入/转换为 Google 文档格式,然后将该文档导出为 PDF。上面的帖子使用 Drive API v2; this follow-up post描述了将其迁移到 Drive API v3,这里是一个 developer video合并两个“穷人的皈依者”帖子。
关于python - Google Drive SDK 快速入门示例 "ImportError: cannot import name util"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12574307/