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

Posted 宁信

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7安装python3和Django后,ModuleNotFoundError: No module named '_sqlite3'相关的知识,希望对你有一定的参考价值。

 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

[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

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 

OK

以上是关于centos7安装python3和Django后,ModuleNotFoundError: No module named '_sqlite3'的主要内容,如果未能解决你的问题,请参考以下文章

CentOS7下部署Django项目详细操作步骤

安装python3后yum不可用

centos7下部署Django(nginx+uWSGI+Python3+Django)

Centos7部署Django+Uwsgi+Nginx环境

centos7下安装配置django,开始第一个项目;

centos7下部署Django(nginx+uwsgi+django+python3)