How to use the latest sqlite3 version in python

寵の児 提交于 2020-12-02 07:22:32

问题


I need to use sqlite version 3.8 or higher with python in Amazon Linux.

I updated my sqlite installation to the latest version:

$ sqlite3 -version
3.22.0 2018-01-22 18:45:57 0c55d179733b46d8d0ba4d88e01a25e10677046ee3da1d5b1581e86726f2171d

I also updated my pysqlite version

pip install --upgrade pysqlite

However, my pysqlite still only seems to support sqlite version 3.7:

$ python
>>> import sqlite3
>>> sqlite3.version
'2.6.0'
>>> sqlite3.sqlite_version
'3.7.17'
>>>
>>> from pysqlite2 import dbapi2 as sqlite
>>> sqlite.version
'2.8.3'
>>> sqlite.sqlite_version
'3.7.17'

How can I update the sqlite python API to support a newer version of sqlite?


回答1:


Two ideas...

  1. Use pyenv to install a separate interpreter, and provide the path to the newer sqlite when creating it. eg:

    PYTHON_CONFIGURE_OPTS="LD_RUN_PATH=/usr/local/opt/sqlite/lib LDFLAGS=-L/usr/local/opt/sqlite/lib CPPFLAGS=-I/usr/local/include" pyenv install 3.4.3
    

    This pyenv issue provides some more details/ideas.

  2. APSW provides an up to date implementation of SQLite, but has different goals from the pysqlite library.

    APSW provides an SQLite 3 wrapper that provides the thinnest layer over the SQLite database library possible. Everything you can do from the SQLite C API, you can do from Python. Although APSW looks vaguely similar to the PEP 249 (DBAPI), it is not compliant with that API because instead it works the way SQLite 3 does. (pysqlite is DBAPI compliant - see the differences between apsw and pysqlite 2).

    APSW embeds the SQLite "amalgamation" distribution statically, so you can safely use it in an environment (eg. Python) which might also have another SQLite loaded.




回答2:


This looks strange. For some reason, updated sqlite version is not reflecting on Python. Download latest python. Extract the tar. Try recomplie, make and install python again. It may work!



来源:https://stackoverflow.com/questions/48865416/how-to-use-the-latest-sqlite3-version-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!