导入 sqlite3 报错:
>>> import sqlite3
Traceback (most recent call last):
File "
File "/usr/local/lib/python3.6/sqlite3/__init__.py", line 23, in
from sqlite3.dbapi2 import *
File "/usr/local/lib/python3.6/sqlite3/dbapi2.py", line 27, in
from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'
方法一:
1、重新安装 sqlite
# yum -y install sqlite-devel
2、重新编译安装Python
#wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tgz
#tar xf Python-3.6.6.tgz
# pwd
/root/tools/Python-3.6.6
# ./configure 提示:可指定安装路径: ./configure --prefix=新路径 (默认/usr/local/bin)
#make
#make install
完成:
[root@dev1 Python-3.6.6]# python3.6
Python 3.6.6 (default, Aug 28 2019, 16:21:34)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
可创建软链接 :创建软连接:ln -s 源路径 目标路径
[root@dev1 ~]# ls -l /usr/bin/python
lrwxrwxrwx 1 root root 24 2月 20 2019 /usr/bin/python -> /usr/local/bin/python3.6
方法二:
系统有安装 sqlite,却还是报错,重装sqlite 也不行;根据网友们得提示,可能是少了个文件:
[root@dev1 Python-3.6.6]# ls /usr/local/lib/python3.6/lib-dynload/_sqlite3.cpython-36m-x86_64-linux-gnu.so
/usr/local/lib/python3.6/lib-dynload/_sqlite3.cpython-36m-x86_64-linux-gnu.so
使用第一个方法前,我也查看了lib-dynload/目录下确实没有:_sqlite3.cpython-36m-x86_64-linux-gnu.so
所以如果有找到该文件,可以拷贝一份到 lib-dynload/目录下,要对应python版本,否则可能报错
这里提供我的:https://download.csdn.net/download/qq_39996858/11632720 .so 文件