centos6 python 安装 sqlite 解决 No module named ‘_sqlite3′

系统red hat6.7 也即centos6.7 python3.5.2 安装 django 之后 创建project 以及 import sqlite3

都出现  No module named ‘_sqlite3′ 

1
2
3
4
5
6
7
>>> import sqlite3
Traceback (most recent call last):
  File "<stdin>", line 1in <module>
  File "/opt/Python-3.5.0/python350/lib/python3.5/sqlite3/__init__.py", line 23in <module>
    from sqlite3.dbapi2 import *
  File "/opt/python-3.5.0/python350/lib/python3.5/sqlite3/dbapi2.py", line 27in <module>
    from _sqlite3 import *


解决:

1
2
3
4
1、yum -y install sqlite-devel
2、cd  Python-3.5.2       (python源码安装文件解压后的文件夹)
3、./configure --enable-loadable-sqlite-extensions 
4、make && make install

如果这几步还不行,就修改 Python-3.5.2文件夹里的setup.py文件以后,重复第三和第四步:

在 sqlite_inc_paths 中添加sqlite的include 路径
如:

1
2
3
4
5
6
7
8
9
 sqlite_inc_paths = [ '/usr/include',
                      '/usr/include/sqlite',
                      '/usr/include/sqlite3',
                      '/usr/local/include',
                      '/usr/local/include/sqlite',
                      '/usr/local/include/sqlite3',
                      '~/share/software/python/sqlite-3.6.20/include',     (~/share/software/python/sqlite-3.6.20是sqlite的安装路径)
                      '~/share/software/python/sqlite-3.6.20/include/sqlite3',
                    ]



二、如果是python2.7出现 import sqlite3 找不到 _sqlite模块的问题,就简单多了

1
2
3
4
5
6
7
1、# find / -name _sqlite*.so
/usr/lib64/python2.6/lib-dynload/_sqlite3.so
2、# whereis python2.7
python2: /usr/bin/python2.7 /usr/bin/python2 /usr/bin/python2.6 /usr/lib/python2.6 
/usr/lib64/python2.6 /usr/local/bin/python2.7 /usr/local/bin/python2.7-config /usr/local/bin/python2 
/usr/local/lib/python2.7 /usr/include/python2.6
3、cp /usr/lib64/python2.6/lib-dynload/_sqlite3.so /usr/local/lib/python2.7/lib-dynload/_sqlite3.so

ok,搞定!



转自:http://blog.csdn.net/jaket5219999/article/details/53512071

本文转自奔跑在路上博客51CTO博客,原文链接http://blog.51cto.com/qiangsh/1939100如需转载请自行联系原作者


qianghong000

上一篇:DataGridView导出到Excel的三个方法


下一篇:session,application,cookie,viewstate,Querystring等的作用域