最近重装了系统之后,发现原有的python3环境下安装sqlite3(见原来博客:ubuntu环境下 python 3.0以上版本对sqlite3的支持问题)的办法已经行不通了。
即使安装了libsqlite-dev之后,仍然会报这样的错误:
omnisky@omnisky:~/work/soft/Python-3.6.2$ python
Python 3.6.2 (default, Jan 21 2018, 10:08:49)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/sqlite3/__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "/usr/local/lib/python3.6/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'针对
针对这个问题,只能采取最原始的办法来进行安装,具体操作如下;
(1)安装sqlite3的包
$ wget https://www.sqlite.org/2017/sqlite-autoconf-3170000.tar.gz --no-check-certificate $ tar zxvf sqlite-autoconf-3170000.tar.gz $ cd sqlite-autoconf-3170000 $ ./configure --prefix=/usr/local/sqlite3 --disable-static --enable-fts5 --enable-json1 CFLAGS="-g -O2 -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_FTS4=1 -DSQLITE_ENABLE_RTREE=1" (2)对python3进行重新编译 $ cd Python-3.6.2 $ LD_RUN_PATH=/usr/local/sqlite3/lib ./configure LDFLAGS="-L/usr/local/sqlite3/lib" CPPFLAGS="-I /usr/local/sqlite3/include" $ LD_RUN_PATH=/usr/local/sqlite3/lib make $ LD_RUN_PATH=/usr/local/sqlite3/lib sudo make install通过上述安装过程,终于可以顺利实现python对sqlite3的支持了。