导入 sqlite3 模块时,出现如下错误:
ModuleNotFoundError: No module named '_sqlite3'
解决方法:
1、编译安装新版 sqlite3:https://bbs.mostop.cn/column/detail.html?detailid=15
2、编译安装 python3:
1)打开网址查看步骤: https://bbs.mostop.cn/column/detail.html?detailid=8
2)在编译安装前修改源码中的 setup.py 文件,找到如下内容,新增 TODO 部分内容
vi setup.py
sqlite_inc_paths = [ '/usr/include',
'/usr/include/sqlite',
'/usr/include/sqlite3',
'/usr/local/include',
'/usr/local/include/sqlite',
'/usr/local/include/sqlite3',
'/usr/local/sqlite3/include', # TODO
]
3)执行上方网址剩下的步骤
4)执行下方代码后,sqlite3 能够正常运行
mv /usr/local/python/lib/python3.8/lib-dynload/_sqlite3.cpython-38-x86_64-linux-gnu_failed.so /usr/local/python/lib/python3.8/lib-dynload/_sqlite3.so
mv /usr/lib64/libsqlite3.so.0 /usr/lib64/libsqlite3.so.0.bak
ln -s /usr/local/sqlite3/lib/libsqlite3.so.0 /usr/lib64/libsqlite3.so.0