python加載sqlite3報錯:No module named _sqlite3

環境爲Ubuntu16.04 Apache2.4 Python2.7.13 django 1.8python

今天部署apache+django,通過各類折騰,好不容易配置完了,發現錯誤Apache的日誌裏有一項linux

ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3sql

因而打開Python 測試下可否導入sqlite3模塊apache

>>> import sqlite3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/sqlite3/__init__.py", line 24, in <module>
    from dbapi2 import *
  File "/usr/local/lib/python2.7/sqlite3/dbapi2.py", line 28, in <module>
    from _sqlite3 import *
ImportError: No module named _sqlite3

django

結果是沒有,我原來使用的是windows,sqlite3已經在安裝包裏了,可是源碼安裝的沒有,是要依賴系統的庫ubuntu

我安裝了以下兩個:windows

sudo apt-get install libsqlite3-dev  centos

sudo apt-get install sqlite3api

PS(我是一直在試,找應該安裝哪一個,有一個就安一個,可是安完以爲可能有多餘的,因此若是你也在安裝的話,能夠先安裝第一個,而後再從新Python2.7,看make時是否提示_sqlite3 須要單獨安裝,以下的話仍是不行,那麼再裝第二個)markdown

Python build finished, but the necessary bits to build these modules were not found:
_bsddb             _sqlite3           _tkinter        
bsddb185           bz2                dbm             
dl                 gdbm               imageop         
readline           sunaudiodev                        
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

上面爲編譯完提示不能一塊兒安裝,須要單獨安裝的提示:

提示:網上的博客不少,可是各自的狀況不同,都須要本身試試

對與sqlite3這個模塊的作法有兩類:

1下載sqlite3模塊sqlite-autoconf-3190300.tar.gz源碼,

  手工配置,編譯,安裝,再配置python安裝下的setup.py   我沒行得通,仍是提示沒法安裝_sqlite3這個提示!

2還有一種是 find / -name "_sqlite3*so" ;而後將此文件 cp到 安裝目錄下的 lib-dynload(一個動態庫文件夾),可是我find的結果是

  _sqlite3.x86_64-linux-gnu.so 並且將其更名拷貝過去仍是不能用

3 安裝依賴包,系統不一樣,包名不一樣(靠譜)

centos下 是 yum install sqlite3-devel -y  #搜索到這個的狀況比較多,我也是基於此說法,才判斷是裝一個dev包就應該能夠

ubuntu 下是 sudo apt-get install libsqlite3-dev 


而後從新make從新安裝python吧

以下提示中沒有了_sqlite3,那麼就沒問題了,並且能夠看下bulid目錄下存在了_sqlite3.so!

Python build finished, but the necessary bits to build these modules were not found:
_bsddb             _ssl               _tkinter        
bsddb185           bz2                dbm             
dl                 gdbm               imageop         
readline           sunaudiodev        zlib            
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

進一步驗證,安裝完成後

1. 方法一:先看下lib是否已經生成_sqlite3.so文件

仍是在 /home/user/usr/python/python2.7/lib/python2.7/lib-dynload 下

發現了 _sqlite3.so 文件

2. 方法二:使用python 命令

>>> import sqlite3 
不報錯便可!
相關文章
相關標籤/搜索