我想将数据从Google驱动器导入数据框。但是我的代码在“从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”的模块
答案 0 :(得分:0)
如果您在本地计算机上运行代码,请尝试使用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'.
答案 1 :(得分:0)
那可能是因为没有安装软件包。使用 PIP 下载并安装它:
pip install google-colab