【问题标题】:GoogleAuth: ModuleNotFoundError: No module named 'google.colab'GoogleAuth:ModuleNotFoundError:没有名为“google.colab”的模块
【发布时间】:2019-10-23 12:10:00
【问题描述】:
我想将数据从谷歌驱动器导入数据框。但是我的代码在“从 google.colab 导入身份验证”步骤中崩溃了。它说找不到 google.colab 模块。
在以下位置尝试过建议
How to resolve: ModuleNotFoundError: No module named 'google.colab'
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
auth.authenticate_user()
import gspread
from oauth2client.client import GoogleCredentials
gc = gspread.authorize(GoogleCredentials.get_application_default())
错误信息:
ModuleNotFoundError:没有名为“google.colab”的模块
【问题讨论】:
标签:
python-3.x
jupyter
google-authentication
【解决方案1】:
如果您在本地机器上运行代码,请尝试使用 PyDrive 从 google 驱动器读取到您的本地机器:
!pip install PyDrive
from pydrive.drive import GoogleDrive
drive = GoogleDrive(gauth)
# Auto-iterate through all files that matches this query
file_list = drive.ListFile({'q': "'root' in parents and trashed=false"}).GetList()
# You can download file content using GetContentFile(filename) by initializing
# GoogleDriveFile instance with file id.
file6 = drive.CreateFile({'id': file5['id']})
file6.GetContentFile('catlove.png') # Download file as 'catlove.png'.
【解决方案2】:
这可能是因为未安装该软件包。使用 PIP 下载并安装它:
pip install google-colab