概述
在安装一些基于python的程序时,经常遇到“ImportError: No module named _sqlite3”问题。
下面记录下解决方法。
![2a14f2f12b0c1f1414e8a95d61ced62b.png](https://i-blog.csdnimg.cn/blog_migrate/ee2c827bea56952dabff0e2ef8717050.jpeg)
解决办法
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*
![3ee1bb4eb6bb012ca2d5de7a8b72bb38.png](https://i-blog.csdnimg.cn/blog_migrate/a152d2c4445eaef9ceb30b5df07dbc29.jpeg)
![22f700c2ad08c443a7324df7031ff3d6.png](https://i-blog.csdnimg.cn/blog_migrate/4c3f034c10164654db73e157eaa569a3.jpeg)
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', ]
![bdd88c62a8bb9a574258f4cb07d6d529.png](https://i-blog.csdnimg.cn/blog_migrate/3d33ad1d90a05992bd812d1b80b950de.jpeg)
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
![5317ca8cd29ccfc099d7ffad159a3fa4.png](https://i-blog.csdnimg.cn/blog_migrate/26adff9a2c97e4c1d2016e9f66e4127d.jpeg)
4、测试
# python>>> import sqlite3
![1735927f8d2226b211dccb4ff72b1aa1.png](https://i-blog.csdnimg.cn/blog_migrate/73ad326558a1e3b2554baf6857b7fcef.jpeg)
觉得有用的朋友多帮忙转发哦!后面会分享更多devops和DBA方面的内容,感兴趣的朋友可以关注下~
![d161d3d712da474f57fbf3102e6593fb.gif](https://i-blog.csdnimg.cn/blog_migrate/705156dac6e6c3039eceb26d9447a383.gif)