解决Python中NO MODULE NAMED _SQLITE3报错的有效方法
发表时间: 2019-09-20 00:02
在安装一些基于python的程序时,经常遇到“ImportError: No module named _sqlite3”问题。
下面记录下解决方法。
1、编译sqlite3或者yum安装sqlite3(建议优先用yum)
wget http://www.sqlite.org/sqlite-amalgamation-3.6.20.tar.gztar -zxvf sqlite-amalgamation-3.6.20.tar.gzcd sqlite-3.5.6./configure -prefix=/usr/local/lib/sqlite3make && make install rm /usr/bin/python /usr/local/python#或者直接yum安装#yum install sqlite*
2、编辑Python文件
修改Python解压目录里的setup.py 文件:在下面这段的下一行添加’
/usr/local/lib/sqlite3/include’,
sqlite_inc_paths = [ '/usr/include', '/usr/include/sqlite', '/usr/include/sqlite3', '/usr/local/include', '/usr/local/include/sqlite', '/usr/local/include/sqlite3', '/usr/local/lib/sqlite3/include', ]
3、重新编译安装Python
./configure --prefix=/usr/local/python --with-openssl=/usr/local/opensslmake && make installln -fs /usr/local/python/bin/python3.7 /usr/bin/pythonln -fs /usr/local/python/bin/pip3 /usr/bin/pip
4、测试
# python>>> import sqlite3
觉得有用的朋友多帮忙转发哦!后面会分享更多devops和DBA方面的内容,感兴趣的朋友可以关注下~