安装 python 3.9 Failed to build these modules: _ctypes 报错解决办法

1、报错信息

2、安装libffi-devel

[root@linuxprobe Python-3.9.1]# yum install libffi-devel
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:13:13 ago on Thu 17 Dec 2020 09:05:04 PM CST.
Dependencies resolved.
=====================================================================================================================================
 Package                            Arch                         Version                          Repository                    Size
=====================================================================================================================================
Installing:
 libffi-devel                       x86_64                       3.1-18.el8                       BaseOS                        28 k

Transaction Summary
=====================================================================================================================================
Install  1 Package

Total size: 28 k
Installed size: 27 k
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                             1/1
  Installing       : libffi-devel-3.1-18.el8.x86_64                                                                              1/1
  Running scriptlet: libffi-devel-3.1-18.el8.x86_64                                                                              1/1
  Verifying        : libffi-devel-3.1-18.el8.x86_64                                                                              1/1
Installed products updated.

Installed:
  libffi-devel-3.1-18.el8.x86_64

Complete!

3、再次make

[root@linuxprobe Python-3.9.1]# make
 CC='gcc -pthread' LDSHARED='gcc -pthread -shared    ' OPT='-DNDEBUG -g -fwrapv -O3 -Wall'      _TCLTK_INCLUDES='' _TCLTK_LIBS=''   ./python -E ./setup.py  build
running build
running build_ext
INFO: Can't locate Tcl/Tk libs and/or headers
building '_ctypes' extension
gcc -pthread -fPIC -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 -I/usr/include -I./Include -I. -I/usr/local/include -I/home/software/Python-3.9.1/Include -I/home/software/Python-3.9.1 -c /home/software/Python-3.9.1/Modules/_ctypes/_ctypes.c -o build/temp.linux-x86_64-3.9/home/software/Python-3.9.1/Modules/_ctypes/_ctypes.o -DPy_BUILD_CORE_MODULE -DHAVE_FFI_PREP_CIF_VAR=1 -DHAVE_FFI_PREP_CLOSURE_LOC=1 -DHAVE_FFI_CLOSURE_ALLOC=1
gcc -pthread -fPIC -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 -I/usr/include -I./Include -I. -I/usr/local/include -I/home/software/Python-3.9.1/Include -I/home/software/Python-3.9.1 -c /home/software/Python-3.9.1/Modules/_ctypes/callbacks.c -o build/temp.linux-x86_64-3.9/home/software/Python-3.9.1/Modules/_ctypes/callbacks.o -DPy_BUILD_CORE_MODULE -DHAVE_FFI_PREP_CIF_VAR=1 -DHAVE_FFI_PREP_CLOSURE_LOC=1 -DHAVE_FFI_CLOSURE_ALLOC=1
gcc -pthread -fPIC -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 -I/usr/include -I./Include -I. -I/usr/local/include -I/home/software/Python-3.9.1/Include -I/home/software/Python-3.9.1 -c /home/software/Python-3.9.1/Modules/_ctypes/callproc.c -o build/temp.linux-x86_64-3.9/home/software/Python-3.9.1/Modules/_ctypes/callproc.o -DPy_BUILD_CORE_MODULE -DHAVE_FFI_PREP_CIF_VAR=1 -DHAVE_FFI_PREP_CLOSURE_LOC=1 -DHAVE_FFI_CLOSURE_ALLOC=1
gcc -pthread -fPIC -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 -I/usr/include -I./Include -I. -I/usr/local/include -I/home/software/Python-3.9.1/Include -I/home/software/Python-3.9.1 -c /home/software/Python-3.9.1/Modules/_ctypes/cfield.c -o build/temp.linux-x86_64-3.9/home/software/Python-3.9.1/Modules/_ctypes/cfield.o -DPy_BUILD_CORE_MODULE -DHAVE_FFI_PREP_CIF_VAR=1 -DHAVE_FFI_PREP_CLOSURE_LOC=1 -DHAVE_FFI_CLOSURE_ALLOC=1
gcc -pthread -fPIC -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 -I/usr/include -I./Include -I. -I/usr/local/include -I/home/software/Python-3.9.1/Include -I/home/software/Python-3.9.1 -c /home/software/Python-3.9.1/Modules/_ctypes/stgdict.c -o build/temp.linux-x86_64-3.9/home/software/Python-3.9.1/Modules/_ctypes/stgdict.o -DPy_BUILD_CORE_MODULE -DHAVE_FFI_PREP_CIF_VAR=1 -DHAVE_FFI_PREP_CLOSURE_LOC=1 -DHAVE_FFI_CLOSURE_ALLOC=1
gcc -pthread -shared build/temp.linux-x86_64-3.9/home/software/Python-3.9.1/Modules/_ctypes/_ctypes.o build/temp.linux-x86_64-3.9/home/software/Python-3.9.1/Modules/_ctypes/callbacks.o build/temp.linux-x86_64-3.9/home/software/Python-3.9.1/Modules/_ctypes/callproc.o build/temp.linux-x86_64-3.9/home/software/Python-3.9.1/Modules/_ctypes/cfield.o build/temp.linux-x86_64-3.9/home/software/Python-3.9.1/Modules/_ctypes/stgdict.o -L/usr/local/lib -lffi -ldl -o build/lib.linux-x86_64-3.9/_ctypes.cpython-39-x86_64-linux-gnu.so

Python build finished successfully!
The necessary bits to build these optional modules were not found:
_dbm                  _gdbm                 _sqlite3
_tkinter              _uuid                 nis
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                  atexit                pwd
time

running build_scripts
copying and adjusting /home/software/Python-3.9.1/Tools/scripts/pydoc3 -> build/scripts-3.9
copying and adjusting /home/software/Python-3.9.1/Tools/scripts/idle3 -> build/scripts-3.9
copying and adjusting /home/software/Python-3.9.1/Tools/scripts/2to3 -> build/scripts-3.9
changing mode of build/scripts-3.9/pydoc3 from 644 to 755
changing mode of build/scripts-3.9/idle3 from 644 to 755
changing mode of build/scripts-3.9/2to3 from 644 to 755
renaming build/scripts-3.9/pydoc3 to build/scripts-3.9/pydoc3.9
renaming build/scripts-3.9/idle3 to build/scripts-3.9/idle3.9
renaming build/scripts-3.9/2to3 to build/scripts-3.9/2to3-3.9
[root@linuxprobe Python-3.9.1]# python
bash: python: command not found...
Failed to search for file: Cannot update read-only repo
[root@linuxprobe Python-3.9.1]# ls
aclocal.m4          config.sub    install-sh      Makefile         Objects         pyconfig.h        python-config.py
build               configure     Lib             Makefile.pre     Parser          pyconfig.h.in     python-gdb.py
CODE_OF_CONDUCT.md  configure.ac  libpython3.9.a  Makefile.pre.in  PC              python            README.rst
config.guess        Doc           LICENSE         Misc             PCbuild         Python            setup.py
config.log          Grammar       m4              Modules          Programs        Python-3.9.1.tgz  Tools
config.status       Include       Mac             netlify.toml     pybuilddir.txt  python-config
[root@linuxprobe Python-3.9.1]# ./python
Python 3.9.1 (default, Dec 17 2020, 21:16:26)
[GCC 8.2.1 20180905 (Red Hat 8.2.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
原文地址:https://www.cnblogs.com/liujiaxin2018/p/14149121.html