[英]ModuleNotFoundError: No module named '_ctypes' Mac M1
While installing some libraries you may find the issue ModuleNotFoundError: No module named '_ctypes'
在安装一些库时,您可能会发现问题
ModuleNotFoundError: No module named '_ctypes'
确保您正在运行 python 3.8.10 +
Short version:精简版:
Try installing python 3.7.13 with pyenv : pyenv install 3.7.13
, and if that does not work, try python 3.7.12 ( pyenv install 3.7.12
).尝试使用 pyenv 安装 python 3.7.13 :
pyenv install 3.7.13
,如果不起作用,请尝试 python 3.7.12 ( pyenv install 3.7.12
)。
The pyenv release 2.2.3 addresses the compilation problems for 3.6.15/3.7.12 on M1 macs, specifically for ctypes . pyenv 版本 2.2.3解决了 M1 mac 上 3.6.15/3.7.12 的编译问题,特别是针对ctypes 。
Long version:长版:
The underlying cause for the _ctypes
error seems to be that libffi cannot be found during the compilation, and is therefore (silently) skipped during the Python installation. _ctypes
错误的根本原因似乎是在编译期间找不到 libffi,因此在 Python 安装期间(默默地)跳过。
There is a comprehensive overview for installing different versions using pyenv at this page , some specific versions require homebrew patches. 在此页面上有使用 pyenv 安装不同版本的全面概述,某些特定版本需要自制补丁。 Here is an overview of those patches .
以下是这些补丁的概述。 However, I would try installing them without the patches first, as the pyenv team has fixed various compilation problems since that post was written.
但是,我会先尝试在不安装补丁的情况下安装它们,因为 pyenv 团队已经修复了自那篇文章撰写以来的各种编译问题。
The general syntax for installing with a patch is: pyenv install --patch XXX <<(curl -sSL link_to_patch)
where XXX
is the version you want to install.使用补丁安装的一般语法是:
pyenv install --patch XXX <<(curl -sSL link_to_patch)
其中XXX
是您要安装的版本。
Another solution is to use an x86 version of homebrew .另一种解决方案是使用 x86 版本的 homebrew 。
Officially, Python 3.7 and lower are not supported on Apple Silicon . Apple Silicon 正式不支持 Python 3.7 及更低版本。
Updating to Python 3.7.13 (or higher versions) should solve the problem.更新到 Python 3.7.13(或更高版本)应该可以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.