为了测试带有 sqlite3 Python 模块的 FTS5 扩展是否有效,我使用了这个code from 技术进步:
import sqlite3
conn = sqlite3.connect(':memory:')
conn.execute("""create virtual table fts5test using fts5 (data);""")
conn.execute("""insert into fts5test (data)
values ('this is a test of full-text search');""")
conn.execute("""select * from fts5test where data match 'full';""").fetchall()
该代码在 Ubuntu 18.04 和 Ubuntu 19.04 上运行良好。例如,可以使用以下 python3.7 解释器通过 Docker 运行它:
docker pull ubuntu:18.04 # This line is optional.
docker run --interactive --tty ubuntu:18.04 bash
apt update
apt install -y software-properties-common
add-apt-repository -y ppa:deadsnakes/ppa
apt update
apt install -y python3.7
python3.7
# use here the python code given above
但是,如果我将 Ubuntu 版本从 18.04 更改为 16.04,则 FTS5 扩展将不起作用:
docker pull ubuntu:16.04 # This line is optional.
docker run --interactive --tty ubuntu:16.04 bash
apt update
apt install -y software-properties-common
add-apt-repository -y ppa:deadsnakes/ppa
apt update
apt install -y python3.7
python3.7
# use here the python code given above
python 代码会崩溃:
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> conn = sqlite3.connect(':memory:')
>>> conn.execute("""create virtual table fts5test using fts5 (data);""")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
sqlite3.OperationalError: no such module: fts5
如何在 Ubuntu 上使用带有 Python 3.7 的 sqlite3 Python 模块的 FTS5 扩展16.04?