[要测试带有sqlite3 Python模块的FTS5扩展是否有效,我使用code中的Vorsprung durch Technik:
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 16.04上将带有FTS5扩展的sqlite3 Python模块和Python 3.7一起使用?