繁体   English   中英

配置 python sqlite3 模块以使用不同的(较新版本)sqlite 系统库(升级 sqlite)

[英]Configure python sqlite3 module to use different (newer version) sqlite system lib (Upgrade sqlite)

We need to use some of the newest sqlite feature like "UPDATE FROM", which is available from sqlite 3.33.0 ( https://www.sqlite.org/changes.html ).

在当前 debian docker 映像中,我们使用稳定(破坏)发行版,它具有旧版本的 sqlite 库(名称为 libsqlite3-dev)。

我从 in.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 库?

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

pip install pysqlite3-binary

在 python 代码中,使用 pysqlite3:

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

而不是 sqlite3

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM