3

我们有一个需要启动的 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
4

1 回答 1

7

重建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
>>> 
于 2013-01-03T19:38:04.393 回答