出现此问题: 我们进入python环境
import sys
sys.path
命令结果如下 :
[图片上传中...(image.png-e5d093-1577110733594-0)]
完成退出 python环境
执行以下命令:
[root@localhost lib-dynload]# find / -name _sqlite3.so
发现在/usr/local/python3/lib/python3.6/lib-dynload/这个路径下没找到_sqlite3.so
但是在/usr/lib64/python2.7/lib-dynload/_sqlite3.so是有这个的; 记住千万不要把python2.7下的_sqlite3.so复制到python3下;是用不了的;
接下来我们开始安装sqlite3:
(1) 下载安装包:wget https://www.sqlite.org/2018/sqlite-autoconf-3240000.tar.gz
(2)解压:tar -xvzf sqlite-autoconf-3240000.tar.gz
(3)进入目录:cd sqlite-autoconf-3240000/
(4)编译:./configure --prefix=/usr/local/sqlite
(5)安装 :make -j4&&sudo make install
安装成功后如下:
此时我们进行重新安装python3
进入python3安装目录 :
[root@localhost sqlite-autoconf-3240000]# cd ../Python-3.6.5/
修改setup.py
[root@localhost Python-3.6.5]# vi setup.py
查找" sqlite_inc_paths" 新增
'/usr/local/sqlite/include'
'/usr/local/sqlite/include/sqlite3'
完成后如下:
保存退出;
执行命令:
[root@localhost Python-3.6.5]# ./configure --enable-loadable-sqlite-extensions
[root@localhost Python-3.6.5]# make && sudo make install
安装完执行以下命令查看_sqlite3.so情况
[r[图片上传中...(image.png-f86dd6-1577110793002-0)]
ot@localhost Python-3.6.5]# find / -name _sqlite*.so
发现python3 多了
/root/Python-3.6.5/build/lib.linux-x86_64-3.6/_sqlite3.cpython-36m-x86_64-linux-gnu.so
/usr/local/lib/python3.6/lib-dynload/_sqlite3.cpython-36m-x86_64-linux-gnu.so
接下来我们在执行:
cp /usr/local/lib/python3.6/lib-dynload/_sqlite3.cpython-36m-x86_64-linux-gnu.so /usr/local/python3/lib/python3.6/lib-dynload/_sqlite3.so
再次进入python环境
执行命令import sqlite3已经可以正常了
如果导入import sqlite3提示,.so文件有问题,
加入export LD_LIBRARY_PATH=/usr/local/sqlite3/lib/:$LD_LIBRARY_PATH到/etc/profile中