Windows mingw环境安装NumPy触发AttributeError错误,求解决方案
安装NumPy时的Meson构建错误解决方法
问题背景
尝试安装manim工具时持续触发NumPy相关安装错误,单独执行pip install numpy仍失败,错误核心为Meson构建系统的异常。
关键错误信息
C:\Users\phoen>pip install numpy Collecting numpy Using cached numpy-1.26.3.tar.gz (15.7 MB) Installing build dependencies ... done Getting requirements to build wheel ... done Installing backend dependencies ... done Preparing metadata (pyproject.toml) ... error error: subprocess-exited-with-error × Preparing metadata (pyproject.toml) did not run successfully. │ exit code: 2 ╰─> [82 lines of output] ... AttributeError: 'NoneType' object has no attribute 'endswith' ... Unknown Windows Python platform 'mingw_x86_64' Unknown Windows Python platform 'mingw_x86_64' ..\..\meson.build:41:12: ERROR: Unhandled python exception This is a Meson bug and should be reported! [end of output] error: metadata-generation-failed × 生成包元数据时遇到错误。 ╰─> 详见上方输出。
错误分析
- 核心问题是Meson构建系统在识别MSYS2的mingw_x86_64 Python平台时出现异常,导致
get_windows_python_arch()返回None,进而触发endswith调用失败 - 当前使用的NumPy 1.26.3依赖的Meson版本(1.2.99)存在该平台识别bug
解决方案
- 强制使用预编译二进制包安装NumPy,跳过源码构建:
pip install numpy --only-binary :all: - 切换到官方Windows版CPython:卸载MSYS2环境中的Python,安装官方发行版后重新执行
pip install numpy - 升级Meson到修复该bug的版本:
pip install meson --upgrade pip install numpy - 安装旧版本NumPy(如1.25.2),该版本对mingw环境兼容性更好:
pip install numpy==1.25.2
内容的提问来源于stack exchange,提问作者Has_Goals
相关产品推荐
相关产品推荐

