歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

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

Copyright © Linux教程網 All Rights Reserved