centos7安装python3和Django后,ModuleNotFoundError: No module named '_sqlite3'

时间:2022-02-06 01:33:58

1.准备安装环境

yum groupinstall 'Development Tools'
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel

2.安装python3

去官网下载编译安装包或者直接执行以下命令下载

wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz

解压

tar -xvJf  Python-3.6.2.tar.xz

切换进入

cd Python-3.6.2

编译安装

./configure prefix=/usr/local/python3

make && make install

安装完毕,/usr/local/目录下就会有python3了

因此我们可以添加软链到执行目录下/usr/bin

ln -s /usr/local/python3/bin/python3 /usr/bin/python3

ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

centos7安装python3和Django后,ModuleNotFoundError: No module named '_sqlite3'

centos7安装python3和Django后,ModuleNotFoundError: No module named '_sqlite3'

[root@greg02 ~]# python3
Python 3.6.2 (default, Nov 15 2017, 03:44:12)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/python3/lib/python3.6/sqlite3/__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "/usr/local/python3/lib/python3.6/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'

3.安装sqlite3

官网http://www.sqlite.org/download.html

我下载的是:sqlite-autoconf-3210000.tar.gz

configure –prefix=/usr/local/sqlite3
make
make install

centos7安装python3和Django后,ModuleNotFoundError: No module named '_sqlite3'

4.安装 sqlite-devel

 yum install sqlite-devel

5.重新编译安装Python3

编辑python3.6.2里面的setup.py,  添加sqlite的搜索路径: 
使用vim setup.py 打开,输入: 
/sqlite_inc_paths #用于寻找该字段,如下所示:

[root@greg02 Python-3.6.2]# vim setup.py

centos7安装python3和Django后,ModuleNotFoundError: No module named '_sqlite3'

centos7安装python3和Django后,ModuleNotFoundError: No module named '_sqlite3'

OK