使用pip安装xdot时遭遇Metadata-Generation Failed Error的技术求助
问题分析与解决:pip安装xdot时Metadata-Generation Failed
问题背景
Windows 10系统下,使用Python 3.12.4、pip 24.0安装xdot时触发pygobject元数据生成失败,核心报错为找不到gobject-introspection-1.0依赖。即使已安装cmake、更新pip/Python,并通过MSYS2安装gobject-introspection,问题仍存在。
报错信息
Preparing metadata (pyproject.toml) ... error error: subprocess-exited-with-error × Preparing metadata (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [24 lines of output] + meson setup #####\AppData\Local\Temp\pip-install-1mh_6ku6\pygobject_894d8c8e7c5f41c08d5b26e56dffd291 C:#####\AppData\Local\Temp\pip-install-1mh_6ku6\pygobject_894d8c8e7c5f41c08d5b26e56dffd291\.mesonpy-4qw_h8dh -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md -Dtests=false -Dwheel=true --wrap-mode=nofallback --native-file=C:######\AppData\Local\Temp\pip-install-1mh_6ku6\pygobject_894d8c8e7c5f41c08d5b26e56dffd291\.mesonpy-4qw_h8dh\meson-python-native-file.ini The Meson build system Version: 1.4.1 Source dir: C:####\Local\Temp\pip-install-1mh_6ku6\pygobject_894d8c8e7c5f41c08d5b26e56dffd291 Build dir: C:####\AppData\Local\Temp\pip-install-1mh_6ku6\pygobject_894d8c8e7c5f41c08d5b26e56dffd291\.mesonpy-4qw_h8dh Build type: native build Project name: pygobject Project version: 3.48.2 C compiler for the host machine: cc (gcc 14.1.0 "cc (Rev3, Built by MSYS2 project) 14.1.0") C linker for the host machine: cc ld.bfd 2.42 Host machine cpu family: x86_64 Host machine cpu: x86_64 Program python3 found: YES (C:\Python311\python.exe) Run-time dependency python found: YES 3.11 Found pkg-config: YES (C:\msys64\ucrt64\bin\pkg-config.EXE) 2.2.0 WARNING: Found CMake 'C:\\Python311\\Scripts\\cmake.EXE' but couldn't run it Found CMake: NO Run-time dependency gobject-introspection-1.0 found: NO (tried pkgconfig and cmake) Not looking for a fallback subproject for the dependency gobject-introspection-1.0 because: Use of fallback dependencies is disabled. ..\meson.build:29:9: ERROR: Dependency 'gobject-introspection-1.0' is required but not found. A full log can be found at ####\AppData\Local\Temp\pip-install-1mh_6ku6\pygobject_894d8c8e7c5f41c08d5b26e56dffd291\.mesonpy-4qw_h8dh\meson-logs\meson-log.txt [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed × Encountered error while generating package metadata. ╰─> See above for output. note: This is an issue with the package mentioned above, not pip. hint: See above for details.
问题原因
- 环境变量配置缺失:MSYS2安装的gobject-introspection库路径未被pkg-config识别,导致Meson无法定位依赖。
- Python环境冲突:报错显示Meson找到的是Python 3.11,与实际使用的3.12.4不一致,存在路径优先级问题。
- CMake兼容性问题:Python环境中的CMake无法被Meson调用,且未使用MSYS2兼容版本的CMake。
解决步骤
步骤1:配置MSYS2环境变量
- 打开MSYS2 UCRT64终端,执行以下命令确认gobject-introspection已安装:
pacman -Q gobject-introspection - 将
C:\msys64\ucrt64\bin添加到系统环境变量PATH的最前端,确保pkg-config优先读取MSYS2下的依赖。
- 打开MSYS2 UCRT64终端,执行以下命令确认gobject-introspection已安装:
步骤2:统一Python环境路径
- 确认系统
PATH中Python 3.12.4的路径(如C:\Python312、C:\Python312\Scripts)优先级高于旧版本Python路径。 - 在MSYS2终端中执行
which python,若显示非3.12.4路径,临时设置路径:export PATH="/c/Python312:/c/Python312/Scripts:$PATH"
- 确认系统
步骤3:修复CMake执行问题
- 卸载Python环境中的CMake:
pip uninstall cmake -y - 通过MSYS2安装兼容版本的CMake:
pacman -S mingw-w64-ucrt-x86_64-cmake
- 卸载Python环境中的CMake:
步骤4:通过MSYS2终端安装xdot
- 打开MSYS2 UCRT64终端,执行:
pip install xdot - 若仍失败,直接安装MSYS2仓库中的xdot:
pacman -S mingw-w64-ucrt-x86_64-xdot
- 打开MSYS2 UCRT64终端,执行:
步骤5:验证安装
- 执行
xdot --version确认安装成功。
- 执行
内容的提问来源于stack exchange,提问作者Viz
相关产品推荐
相关产品推荐

