Traceback (most recent call last):
File “/usr/local/lib/python3.7/site-packages/sqlalchemy/dialects/sqlite/pysqlite.py”, line 338, in dbapi
from pysqlite2 import dbapi2 as sqlite
ModuleNotFoundError: No module named ‘pysqlite2’‘
解决方法:
1.将pysqlite.py中引用的pysqlite2替换为pysqlite3
sed -i ‘s/sqlite2/sqlite3/g’ /usr/local/lib/python3.7/site-packages/sqlalchemy/dialects/sqlite/pysqlite.py
2.如果还报错ModuleNotFoundError: No module named ‘pysqlite3’‘
yum -y install sqlite-devel
#python3
import sys
sys.path
[’’, ‘/usr/local/lib/python37.zip’, ‘/usr/local/lib/python3.7’, ‘/usr/local/lib/python3.7/lib-dynload’, ‘/usr/local/lib/python3.7/site-packages’]
#find / -name _sqlite3*
/usr/lib64/python2.7/lib-dynload/_sqlite3.so
将此文件cp到/usr/local/lib/python3.7/lib-dynload下
3.执行后如果使用pysqlite后报:ImportError: dynamic module does not define module export function (PyInit__sqlite3)错误
解决方法:
安装sqlite3
#https://www.sqlite.org/2017/sqlite-autoconf-3170000.tar.gz --no-check-certificate
#tar sqlite-autoconf-3300100.tar.gz
#cd sqlite-autoconf-3300100
#./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"
#make && make install
重新编译python3
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 make install