No module named '_ctypes'

当编译安装的python导入types模块出错时,一般是编译安装python之前没有安装libffi-devel。报错信息如下:

# python
Python 3.7.5 (default, Nov  3 2020, 14:56:19) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/python37/lib/python3.7/ctypes/__init__.py", line 7, in 
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
>>> 

这里需要安装libffi-devel,重新编译安装python。执行命令如下:

yum install libffi-devel -y    ----需要换成默认的python,否则会yum报错
cd Python-3.7.5/
make clean && make && make install

你可能感兴趣的:(No module named '_ctypes')