python 在linux中使用sqlite3

时间:2022-06-10 01:17:45

python 在linux中使用sqlite3  



如果出现如下错误:
>>> import sqlite3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/picb/extprog/inst/development/python-2.6.2-linux-amd64/lib/python2.6/sqlite3/__init__.py", line 24, in <module>
    from dbapi2 import *
  File "/picb/extprog/inst/development/python-2.6.2-linux-amd64/lib/python2.6/sqlite3/dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ImportError: No module named _sqlite3
可以尝试如下办法:
(1) 安装sqlite3
下载 sqlite (如sqlite-amalgamation-3.6.20.tar.gz)
安装sqlite, 如果要安装到用户指定目录,可以: $./configure --prefix=/your/path/
(2) 重新安装python
2.1 先修改python 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/include/sqlite3',
                           ]
2.2 安装python
如果要安装到指定目录,可以使用prefix, $./configure --prefix=/your/path/
(3) 检测安装是否成功
>>import sqlite3

来自: http://gcxieblog.blog.163.com
参考:  http://www.mangbar.com/document/8a80809d1a15cbb7011a33a15a7c64bc