ModuleNotFoundError: No module named ‘_ctypes‘的解决方案

腾讯云Linux服务器上安装Python3时,报错

    import ctypes
  File "/usr/local/python3/lib/python3.7/ctypes/__init__.py", line 7, in <module>
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'

原因:

Python3中有个内置模块叫ctypes,它是Python3的外部函数库模块,它提供兼容C语言的数据类型,并通过它调用Linux系统下的共享库(Shared library),此模块需要使用CentOS7系统中外部函数库(Foreign function library)的开发链接库(头文件和链接库)。
由于在CentOS7系统中没有安装外部函数库(libffi)的开发链接库软件包,所以在安装pip的时候就报"ModuleNotFoundError: No module named '_ctypes'"。

 

解决问题步骤:

1、终端执行:

yum install libffi-devel -y

2、使用yum安装python3,使用源码安装python3请访问:https://blog.csdn.net/KingOfOnePiece/article/details/113262318

yum install python

python安装完成时,会自动安装setuptools和pip。

 

检查安装结果:

[root@VM-0-5-centos Python-3.7.4]# python3 -V
Python 3.7.4
[root@VM-0-5-centos Python-3.7.4]# pip3 -V
pip 19.0.3 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
引用提到了解决"ModuleNotFoundError: No module named '_ctypes'"错误的原因是在CentOS7系统没有安装外部函数库(libffi)的开发链接库软件包。要解决这个问题,你可以按照下面的步骤进行操作: 1. 确保你的系统已经安装了pip工具。 2. 在终端执行以下命令安装libffi的开发链接库软件包: ``` sudo yum install libffi-devel ``` 3. 安装完成后,再次运行pip命令看是否还会出现该错误。 引用提到了另一个错误"pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.",这个错误是因为Python的ssl模块不可用导致的。要解决这个问题,你可以按照以下步骤进行操作: 1. 确保你的系统已经安装了openssl软件包。你可以使用以下命令进行安装: ``` sudo apt-get install openssl ``` 2. 确保你的系统已经安装了libssl-dev软件包。你可以使用以下命令进行安装: ``` sudo apt-get install libssl-dev ``` 3. 安装完成后,再次运行pip命令看是否还会出现该错误。 希望以上的解决方案能够帮助你解决问题。如果还有其他疑问,请随时提问。123 #### 引用[.reference_title] - *1* [ModuleNotFoundError: No module named ‘_ctypes‘解决方法](https://blog.csdn.net/wuyepiaoxue789/article/details/117958240)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] - *2* *3* [Python安装报错:”ModuleNotFoundError:No module named _ctypes“ 的解决方案](https://blog.csdn.net/qq_42353939/article/details/94609591)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] [ .reference_list ]
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值