如何使用python访问谷歌驱动器中的SQLite数据库



目标是使用jupyter笔记本操作存储在谷歌驱动器中的SQLite数据库。我找到了一种使用谷歌协作器访问谷歌驱动器中SQLite数据库的方法,但我不知道如何在jupyter笔记本中做到这一点。

使用以下代码,我可以访问谷歌驱动器,但无法连接到SQLite数据库。

我如何修改";conn=sqlite3.connect(驱动器路径+数据库名称("?

如果你能告诉我,我将不胜感激。

#####################

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
gauth.LocalWebserverAuth() # Creates local webserver and auto handles authentication.
drive = GoogleDrive(gauth)

import sqlite3
drive_path = "/My Drive/database/"
db_name = "test.db"
conn = sqlite3.connect(drive_path + db_name)
cur = conn.cursor()

不知道我的解决方案是否适合您。您可能已经知道,由于Sqlite仅基于文件,因此数据库文件必须位于网络共享文件夹中。在我的Mac上,我将谷歌硬盘作为文件夹安装在本地硬盘中,然后将谷歌硬盘数据库文件作为常规本地文件访问:

conn = sqlite3.connect('/Users/local/Google Drive (xxxx@gmail.com)/sample.db')

最新更新