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

安装peewee后不支持pysqlite,安装pysqlite3时编译失败求助

解决pysqlite3编译失败及Peewee适配问题

从编译错误日志来看,问题出在pysqlite3编译时无法找到系统SQLite库的扩展函数(sqlite3_enable_load_extension、sqlite3_load_extension),同时macOS部署目标版本过低也触发了警告。以下是几种可行的解决办法:

方案一:安装预编译二进制包(最简便)

跳过本地编译,直接安装官方提供的预编译版本:

pip install pysqlite3-binary

安装完成后,Peewee会自动适配该库,无需额外配置。

方案二:升级SQLite并指定编译路径

如果需要使用系统级SQLite,先通过Homebrew升级到新版:

brew install sqlite3

然后安装pysqlite3时指定头文件和库路径:

CFLAGS="-I$(brew --prefix sqlite3)/include" LDFLAGS="-L$(brew --prefix sqlite3)/lib" pip install pysqlite3

方案三:直接使用Python自带SQLite模块

Peewee原生支持Python标准库中的sqlite3,无需额外安装pysqlite3。检查代码中是否强制指定了pysqlite3,若没有,直接使用默认驱动即可:

from peewee import SqliteDatabase, Model, CharField

db = SqliteDatabase('your_database.db')

class ExampleModel(Model):
    name = CharField()

    class Meta:
        database = db

验证方法

运行以下代码确认连接正常:

from peewee import SqliteDatabase

db = SqliteDatabase('test.db')
try:
    db.connect()
    print("SQLite连接成功")
finally:
    db.close()

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 13:39:55