You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows下使用connectorx连接SQLite3数据库路径冒号丢失问题解决

在Windows系统下使用connectorx连接SQLite数据库的正确方式

你遇到的问题是connectorx对Windows路径的连接字符串解析规则导致的:当使用sqlite://E:/my_db.db时,库会把E:误识别为连接的主机名,最终路径被错误处理为E/my_db.db(丢失了盘符后的冒号)。

解决方法是在连接字符串中使用三个斜杠来明确指定本地绝对路径,以下是两种可行的写法:

方法1:使用正斜杠路径

import connectorx as cx
# 直接构造连接字符串
conn = 'sqlite:///E:/my_db.db'
# 或者通过变量拼接
db_path = 'E:/my_db.db'
conn = 'sqlite:///' + db_path

# 执行查询
cx.read_sql(conn, 'select * from tablename')

方法2:使用Windows原生反斜杠

如果习惯用反斜杠路径,需要注意字符串转义(或使用原始字符串):

# 转义反斜杠
conn = 'sqlite:///E:\\my_db.db'
# 或者用原始字符串
conn = r'sqlite:///E:\my_db.db'

cx.read_sql(conn, 'select * from tablename')

这样设置后,connectorx就能正确识别Windows的盘符路径,不会再出现路径冒号丢失的问题。

内容的提问来源于stack exchange,提问作者the_economist

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 00:05:28