./python -E ./setup.py install \
--prefix=/usr/local/python3 \
--install-scripts=/usr/local/python3/bin \
--install-platlib=/usr/local/python3/lib/python3.10/lib-dynload \
--root=/
running install
running build
running build_ext
INFO: Can't locate Tcl/Tk libs and/or headers
building '_ctypes' extension
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -fvisibility=hidden -I./Include/internal -fPIC -I./Include -I/usr/local/python3/include -I. -I/usr/local/include -I/root/Python-3.10.5/Include -I/root/Python-3.10.5 -c /root/Python-3.10.5/Modules/_ctypes/_ctypes.c -o build/temp.linux-x86_64-3.10/root/Python-3.10.5/Modules/_ctypes/_ctypes.o -DPy_BUILD_CORE_MODULE
/root/Python-3.10.5/Modules/_ctypes/_ctypes.c:107:17: 致命错误:ffi.h:没有那个文件或目录
#include <ffi.h>
^
编译中断。
Python build finished successfully!
The necessary bits to build these optional modules were not found:
_bz2 _curses _curses_panel
_dbm _gdbm _hashlib
_lzma _sqlite3 _ssl
_tkinter _uuid readline
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
_abc pwd time
Failed to build these modules:
_ctypes
Could not build the ssl module!
Python requires a OpenSSL 1.1.1 or newer
解决办法:
- Python3中有个内置模块叫ctypes,它是Python3的外部函数库模块,它提供兼容C语言的数据类型,并通过它调用Linux系统下的共享库(Shared library),此模块需要使用CentOS7系统中外部函数库(Foreign function library)的开发链接库(头文件和链接库)。
由于在CentOS7系统中没有安装外部函数库(libffi)的开发链接库软件包,所以编译的时候会报错,安装外部函数库(libffi) yum install libffi-devel -y 就可以了 - 安装openssl1.1.1q版本,build python源码的时候启用./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl --with-openssl-rpath=no