环境
# cat /etc/redhat-release
CentOS release 6.8 (Final)
$ which python3.6
/usr/local/bin/python3.6
# find /usr/local -name _sqlite3.so
/usr/local/lib/python2.7/lib-dynload/_sqlite3.so
# yum install sqlite-devel
当我使用 SQLite3 时,发生错误
No module named '_sqlite3'
我决定再次从源代码构建它。
# ./configure --enable-shared --prefix=/usr/local LDFLAGS="-Wl,-rpath /usr/local/lib" --with-sqlite=/usr/local/lib/python2.7/lib-dynload/_sqlite3.so
# make
Python build finished successfully!
Following modules built successfully but were removed because they could not be imported: _sqlite3
·为什么?
最佳答案
/usr/local/lib/python2.7/lib-dynload/_sqlite3.so
是 Python 2 Python 包装器模块,而不是实际的 SQLite 库。此外,--with-sqlite
应该指向 标题 ,而不是共享库。编译需要头文件,动态库位于运行时。
不是说你需要使用--with-sqlite
一旦你安装了sqlite-devel
header ;它们被放置在 Python 配置脚本知道如何找到的默认位置,在 usr/include
中.只有当您在非默认位置有标题时,您才会使用该选项指向保存 sqlite3.h
的目录。和 sqlite3ext.h
标题。
编译后,sqlite3
Python 模块加载 _sqlite3*.so
扩展模块(确切名称与确切的 Python 3 版本和平台不同),动态加载器将找到正确的 libsqlite3.so
版本。
关于python-3.x - 无法导入 : _sqlite3 /Python3. 6 / CentOS6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44281547/