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

原文连接:

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

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

都出现  No module named ‘_sqlite3′ 

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

 

解决:

1、yum -y install sqlite-devel

2、cd  Python-3.5.2       (python源码安装文件解压后的文件夹)

3、./configure --enable-loadable-sqlite-extensions --prefix=/opt/Python352     (--prefix可加可不加)

4、 make && make install

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

在 sqlite_inc_paths 中添加sqlite的include 路径
如:
        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、# 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,搞定!

posted @ 2017-06-17 19:04  扫驴  阅读(4714)  评论(0编辑  收藏  举报