我们在安装一些基于python的程序时,经常遇到“ImportError: No module named _sqlite3”问题。
解决办法:需先编译sqlite3.
wget http://www.sqlite.org/sqlite-amalgamation-3.6.20.tar.gz
tar zxvf sqlite-amalgamation-3.6.20.tar.gz
cd sqlite-3.5.6
./configure –prefix=/usr/local/lib/sqlite3
make
make install (这样,sqlite3编译完成)
rm /usr/bin/python /usr/local/bin/python
再来编译python2.7:
wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tar.bz2
tar jxvf Python-2.7.6.tar.bz2
cd Python-2.7.6
先修改Python-2.7.6目录里的setup.py 文件:
在下面这段的下一行添加’/usr/local/lib/sqlite3/include’,
sqlite_inc_paths = [ ‘/usr/include’,
‘/usr/include/sqlite’,
‘/usr/include/sqlite3′,
‘/usr/local/include’,
‘/usr/local/include/sqlite’,
‘/usr/local/include/sqlite3′,
‘/usr/local/lib/sqlite3/include’,
然后
./configure
make
make install (这样,python2.7编译完成)
as3:~/Python-2.7.6# python -V
Python 2.7.6
as3:~/Python-2.7.6# python
Python 2.7.6 (default, Nov 20 2013, 07:15:04)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> (此处无“ImportError: No module named _sqlite3”的出错提示,表明导入sqlite3成功)
同时也解决了“ImportError: No module named time”问题。
编译完python后,会提示:
Python build finished, but the necessary bits to build these modules were not found:
_tkinter bsddb185 bz2
gdbm readline sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module’s name.解决办法也是修改Python-2.7.6目录里的setup.py 文件。