1 year ago
#385382
刘江斌
After compiling and installing Python 3.9.2 on centos6.8, the library sqlite3 cannot be used
In centos6.8, I use the following command to install Python:
tar -zxf Python-3.9.2.tgz
cd Python-3.9.2
./configure --prefix=/usr/local/python-3.9.2
make
make install
Then, start the Python command line, try to import sqlite3, but failed:
Python 3.9.2 (default, Apr 7 2022, 11:39:04)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/x2openEuler-python-3.9.2/lib/python3.9/sqlite3/__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "/usr/local/x2openEuler-python-3.9.2/lib/python3.9/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'
sqlite
and sqlite-devel
is already installed:
[root@centos68 ~]# rpm -qa | grep sqlite
libdbi-dbd-sqlite-0.8.3-5.1.el6.x86_64
sqlite-devel-3.6.20-1.el6_7.2.x86_64
sqlite-3.6.20-1.el6_7.2.x86_64
...
So I guessed that the versions of sqlite
and sqlite-devel
were too low, then I looked at the setup.py
file for Python-3.9.2, the constant MIN_SQLITE_VERSION_NUMBER
indicates that the minimum version is 3.7.2:
def detect_sqlite(self):
# The sqlite interface
sqlite_setup_debug = False # verbose debug prints from this script?
# We hunt for #define SQLITE_VERSION "n.n.n"
# We need to find >= sqlite version 3.3.9, for sqlite3_prepare_v2
sqlite_incdir = sqlite_libdir = None
sqlite_inc_paths = [ '/usr/include',
'/usr/include/sqlite',
'/usr/include/sqlite3',
'/usr/local/include',
'/usr/local/include/sqlite',
'/usr/local/include/sqlite3',
]
if CROSS_COMPILING:
sqlite_inc_paths = []
MIN_SQLITE_VERSION_NUMBER = (3, 7, 2)
MIN_SQLITE_VERSION = ".".join([str(x)
for x in MIN_SQLITE_VERSION_NUMBER])
So I recompiled and installed sqlite-3.7.4 (download url: https://github.com/sqlite/sqlite/archive/refs/tags/version-3.7.4.tar.gz):
./configure --prefix=/usr/local/sqlite
make
make install
modify setup.py
, append /usr/local/sqlite/include
and /usr/local/sqlite/include/sqlite3
in the sqlite_inc_paths
:
def detect_sqlite(self):
# The sqlite interface
sqlite_setup_debug = False # verbose debug prints from this script?
# We hunt for #define SQLITE_VERSION "n.n.n"
# We need to find >= sqlite version 3.3.9, for sqlite3_prepare_v2
sqlite_incdir = sqlite_libdir = None
sqlite_inc_paths = [ '/usr/include',
'/usr/include/sqlite',
'/usr/include/sqlite3',
'/usr/local/include',
'/usr/local/include/sqlite',
'/usr/local/include/sqlite3',
'/usr/local/sqlite/include',
'/usr/local/sqlite/include/sqlite3',
]
if CROSS_COMPILING:
sqlite_inc_paths = []
MIN_SQLITE_VERSION_NUMBER = (3, 7, 2)
MIN_SQLITE_VERSION = ".".join([str(x)
for x in MIN_SQLITE_VERSION_NUMBER])
Then, recompiled and install Python-3.9.2, but it's still not work. In the compilation log, I found a warning like the following:
+ make install
/root/liujiangbin/sources/Python-3.9.2/Modules/_ctypes/callbacks.c: In function ‘_ctypes_alloc_callback’:
/root/liujiangbin/sources/Python-3.9.2/Modules/_ctypes/callbacks.c:434: Error:#pragma GCC diagnostic is not allowed in function body
/root/liujiangbin/sources/Python-3.9.2/Modules/_ctypes/callbacks.c:435: Error:#pragma GCC diagnostic is not allowed in function body
/root/liujiangbin/sources/Python-3.9.2/Modules/_ctypes/callbacks.c:443: Error:#pragma GCC diagnostic is not allowed in function body
*** WARNING: renaming "_sqlite3" since importing it failed: build/lib.linux-x86_64-3.9/_sqlite3.cpython-39-x86_64-linux-gnu.so: undefined symbol: sqlite3_create_function_v2
python
python-3.x
linux
sqlite
gcc
0 Answers
Your Answer