Python 2.7.3 _sqlite3 module is not being built af

2019-04-12 09:29发布

We have a Django project we need to start and cannot build sqlite for the persistent store.

sqlite3-dev headers/libs are not installed in the system by default
I have no root permissions on this box (we are expected to install all we need)
I compiled/installed Python-2.7.3 in /opt/python/current2
I downloaded and compiled sqlite3 source in /home/olib/sqlite-autoconf-307150
I downloaded pysqlite-2.6.3
I modified pysqlite-2.6.3/setup.py to point to my sqlite3 source header and library files

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  

for some reason "_sqlite.so" is built but not "_sqlite3.so" of course this causes Django import to fail

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

1条回答
女痞
2楼-- · 2019-04-12 10:11

rebuilt Python with

./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 now created!
Copied to lib-dynload directory

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

All looks good now..

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
>>> 
查看更多
登录 后发表回答