【问题标题】:Configure python sqlite3 module to use different (newer version) sqlite system lib (Upgrade sqlite)配置 python sqlite3 模块以使用不同的(较新版本)sqlite 系统库(升级 sqlite)
【发布时间】:2021-03-16 15:23:53
【问题描述】:

我们需要使用一些最新的 sqlite 功能,例如“UPDATE FROM”,该功能可从 sqlite 3.33.0 (https://www.sqlite.org/changes.html) 获得。

在当前的 debian docker 镜像中,我们使用 stable (buster) 发行版,它具有旧版本的 sqlite lib(名称为 libsqlite3-dev)。

我从 .sh 脚本中的源代码本地编译了 sqlite3,但我无法将 pythons sqlite3 模块配置为使用刚刚编译的 sqlite 版本。

代码如下所示:

# Download newer libsqlite3-dev with "UPDATE FROM" clause support
cd data_processing
wget "https://www.sqlite.org/2020/sqlite-amalgamation-3340000.zip" -O sqlite.zip
unzip sqlite.zip
rm sqlite.zip
mv sqlite-amalgamation-3340000 sqlite-3.34
cd sqlite-3.34
gcc shell.c sqlite3.c -lpthread -ldl -o sqlite3
# remove no longer needed file (everything else than just created sqlite3)
find . ! -name 'sqlite3' -type f -exec rm -f {} +
cd -
export PATH="$(pwd)/my_app/sqlite-3.34:$PATH"

在这里我们可以看到,将二进制文件添加到路径中是不够的。 我也尝试添加:

sys.path.insert(
    0,
    '/home/user/project/libs/my_app/sqlite-3.34'
)

进入python代码,没有成功。 有没有办法配置 sqlite3 python 模块以使用系统上安装的不同 sqlite 库?

【问题讨论】:

标签: python sqlite


【解决方案1】:

使用pysqlite3的二进制包: https://github.com/coleifer/pysqlite3 在您的要求中,添加

pip install pysqlite3-binary

在python代码中,使用pysqlite3:

import pysqlite3
    (...) conn = pysqlite3.connect(r"filename") (...)

而不是 sqlite3

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多