简体   繁体   English

无法导入它们:_sqlite3 /Python3.6 / CentOS6

[英]they could not be imported: _sqlite3 /Python3.6 / CentOS6

Environment 环境

# cat /etc/redhat-release

CentOS release 6.8 (Final) CentOS版本6.8(最终版)

$ which python3.6

/usr/local/bin/python3.6 /usr/local/bin/python3.6

# find /usr/local -name _sqlite3.so

/usr/local/lib/python2.7/lib-dynload/_sqlite3.so /usr/local/lib/python2.7/lib-dynload/_sqlite3.so

# yum install sqlite-devel

When I usr SQLite3, Error occurred 当我使用usr SQLite3时,发生错误

No module named '_sqlite3' 没有名为“ _sqlite3”的模块


I decided to build it from source again. 我决定再次从源代码构建它。

# ./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! Python构建成功完成!

Following modules built successfully but were removed because they could not be imported: _sqlite3 以下模块已成功构建,但由于无法导入而被删除:_sqlite3

・Why? ·为什么?

/usr/local/lib/python2.7/lib-dynload/_sqlite3.so is the Python 2 Python wrapper module and not the actual SQLite library. /usr/local/lib/python2.7/lib-dynload/_sqlite3.so是Python 2 Python包装器模块,而不是实际的SQLite库。 Moreover, --with-sqlite should point to the headers , not the shared library. 此外,-- --with-sqlite应该指向标头 ,而不是共享库。 Compilation requires the headers, the dynamic library is located at runtime. 编译需要头文件,动态库位于运行时。

Not that you need to use --with-sqlite once you installed the sqlite-devel headers; 安装sqlite-devel标头后,您不必使用--with-sqlite those are put in a default location that the Python configure script knows how to find, in usr/include . 将它们放在usr/include中的Python配置脚本知道如何查找的默认位置。 Only if you have headers in a non-default location would you use that option to point to the directory holding the sqlite3.h and sqlite3ext.h headers. sqlite3ext.h文件位于非默认位置时,才可以使用该选项指向包含sqlite3.hsqlite3ext.h头文件的目录。

Once compiled, the sqlite3 Python module loads the _sqlite3*.so extension module (the exact name differs with the exact Python 3 release and platform), and the dynamic loader will find the right libsqlite3.so version. 编译后, sqlite3 Python模块将加载_sqlite3*.so扩展模块(确切的名称与确切的Python 3版本和平台不同),动态加载程序将找到正确的libsqlite3.so版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM