传递头文件/库后,没有构建Python 2.7.3 _sqlite3模块

我们需要启动一个Django项目,不能为持久性存储构建sqlite.

默认情况下,系统中未安装sqlite3-dev headers / libs
我在这个盒子上没有root权限(我们希望安装我们需要的所有权限)
我在/ opt / python / current2中编译/安装了Python-2.7.3
我在/ home / olib / sqlite-autoconf-307150中下载并编译了sqlite3源代码
我下载了pysqlite-2.6.3
我修改了pysqlite-2.6.3 / setup.py来指向我的sqlite3源头文件和库文件

include_dirs = ['/home/olib/sqlite-autoconf-3071501']  
library_dirs = ['/home/olib/sqlite-autoconf-3071501/.libs']

/home/olib/pysqlite-2.6.3> echo $PYTHON_HOME  
/opt/python/current2

/home/olib/pysqlite-2.6.3> python setup.py install  
running install  
running build  
running build_py  
creating build  
creating build/lib.linux-x86_64-2.7  
creating build/lib.linux-x86_64-2.7/pysqlite2  
copying lib/dbapi2.py -> build/lib.linux-x86_64-2.7/pysqlite2  
copying lib/dump.py -> build/lib.linux-x86_64-2.7/pysqlite2  
copying lib/__init__.py -> build/lib.linux-x86_64-2.7/pysqlite2  
creating build/lib.linux-x86_64-2.7/pysqlite2/test  
copying lib/test/dbapi.py -> build/lib.linux-x86_64-2.7/pysqlite2/test  
copying lib/test/userfunctions.py -> build/lib.linux-x86_64-2.7/pysqlite2/test  
copying lib/test/types.py -> build/lib.linux-x86_64-2.7/pysqlite2/test  
copying lib/test/dump.py -> build/lib.linux-x86_64-2.7/pysqlite2/test  
copying lib/test/regression.py -> build/lib.linux-x86_64-2.7/pysqlite2/test  
copying lib/test/hooks.py -> build/lib.linux-x86_64-2.7/pysqlite2/test  
copying lib/test/factory.py -> build/lib.linux-x86_64-2.7/pysqlite2/test  
copying lib/test/transactions.py -> build/lib.linux-x86_64-2.7/pysqlite2/test  
copying lib/test/__init__.py -> build/lib.linux-x86_64-2.7/pysqlite2/test  
creating build/lib.linux-x86_64-2.7/pysqlite2/test/py25  
copying lib/test/py25/py25tests.py -> build/lib.linux-x86_64-2.7/pysqlite2/test/py25  
copying lib/test/py25/__init__.py -> build/lib.linux-x86_64-2.7/pysqlite2/test/py25  
running build_ext  
building 'pysqlite2._sqlite' extension  
creating build/temp.linux-x86_64-2.7  
creating build/temp.linux-x86_64-2.7/src  
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DMODULE_NAME="pysqlite2.dbapi2" -DSQLITE_OMIT_LOAD_EXTENSION=1 -I/home/olib/sqlite-autoconf-3071501 -I/opt/python/current2/include/python2.7 -c src/module.c -o build/temp.linux-x86_64-2.7/src/module.o  
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DMODULE_NAME="pysqlite2.dbapi2" -DSQLITE_OMIT_LOAD_EXTENSION=1 -I/home/olib/sqlite-autoconf-3071501 -I/opt/python/current2/include/python2.7 -c src/connection.c -o build/temp.linux-x86_64-2.7/src/connection.o  
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DMODULE_NAME="pysqlite2.dbapi2" -DSQLITE_OMIT_LOAD_EXTENSION=1 -I/home/olib/sqlite-autoconf-3071501 -I/opt/python/current2/include/python2.7 -c src/cursor.c -o build/temp.linux-x86_64-2.7/src/cursor.o  
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DMODULE_NAME="pysqlite2.dbapi2" -DSQLITE_OMIT_LOAD_EXTENSION=1 -I/home/olib/sqlite-autoconf-3071501 -I/opt/python/current2/include/python2.7 -c src/cache.c -o build/temp.linux-x86_64-2.7/src/cache.o  
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DMODULE_NAME="pysqlite2.dbapi2" -DSQLITE_OMIT_LOAD_EXTENSION=1 -I/home/olib/sqlite-autoconf-3071501 -I/opt/python/current2/include/python2.7 -c src/microprotocols.c -o build/temp.linux-x86_64-2.7/src/microprotocols.o  
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DMODULE_NAME="pysqlite2.dbapi2" -DSQLITE_OMIT_LOAD_EXTENSION=1 -I/home/olib/sqlite-autoconf-3071501 -I/opt/python/current2/include/python2.7 -c src/prepare_protocol.c -o build/temp.linux-x86_64-2.7/src/prepare_protocol.o  
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DMODULE_NAME="pysqlite2.dbapi2" -DSQLITE_OMIT_LOAD_EXTENSION=1 -I/home/olib/sqlite-autoconf-3071501 -I/opt/python/current2/include/python2.7 -c src/statement.c -o build/temp.linux-x86_64-2.7/src/statement.o  
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DMODULE_NAME="pysqlite2.dbapi2" -DSQLITE_OMIT_LOAD_EXTENSION=1 -I/home/olib/sqlite-autoconf-3071501 -I/opt/python/current2/include/python2.7 -c src/util.c -o build/temp.linux-x86_64-2.7/src/util.o  
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DMODULE_NAME="pysqlite2.dbapi2" -DSQLITE_OMIT_LOAD_EXTENSION=1 -I/home/olib/sqlite-autoconf-3071501 -I/opt/python/current2/include/python2.7 -c src/row.c -o build/temp.linux-x86_64-2.7/src/row.o

gcc -pthread -shared build/temp.linux-x86_64-2.7/src/module.o build/temp.linux-x86_64-2.7/src/connection.o build/temp.linux-x86_64-2.7/src/cursor.o build/temp.linux-x86_64-2.7/src/cache.o build/temp.linux-x86_64-2.7/src/microprotocols.o build/temp.linux-x86_64-2.7/src/prepare_protocol.o build/temp.linux-x86_64-2.7/src/statement.o build/temp.linux-x86_64-2.7/src/util.o build/temp.linux-x86_64-2.7/src/row.o -L/home/olib/sqlite-autoconf-3071501/.libs -lsqlite3 -o build/lib.linux-x86_64-2.7/pysqlite2/**_sqlite.so**  
running install_lib  
copying build/lib.linux-x86_64-2.7/pysqlite2/_sqlite.so -> /opt/python/current2/lib/python2.7/site-packages/pysqlite2  
running install_data  
running install_egg_info  
Removing /opt/python/current2/lib/python2.7/site-packages/pysqlite-2.6.3-py2.7.egg-info  
Writing /opt/python/current2/lib/python2.7/site-packages/pysqlite-2.6.3-py2.7.egg-info  

出于某种原因“_sqlite.so”已构建但不是“_sqlite3.so”当然这会导致Django导入失败

File "/opt/python/current2/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 31, in <module>
raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc)
django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3

最佳答案 重建Python

./configure --prefix=/opt/python/ LDFLAGS='-L/home/olib/sqlite-autoconf-3071501/.libs'     CPPFLAGS="-I/home/olib/sqlite-autoconf-3071501/'  

./build/lib.linux-x86_64-2.7/_sqlite3.so现在已创建!
复制到lib-dynload目录

olib:~/Python-2.7.3> cp ./build/lib.linux-x86_64-2.7/_sqlite3.so /opt/python/current2/lib/python2.7/lib-dynload/

一切看起来都很好..

olib:~> python
Python 2.7.3 (default, May 28 2012, 20:04:45) 
[GCC 4.1.2 20070115 (prerelease) (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> 
点赞