使用pip安装pandas时遭遇Preparing metadata (pyproject.toml)执行失败错误
执行pip install pandas(已升级pip)时,在Preparing metadata (pyproject.toml)步骤失败,meson构建系统报错无法解析vswhere.exe的输出,完整报错日志如下:
pip install pandas Collecting pandas Using cached pandas-2.1.4.tar.gz (4.3 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: 1 ╰─> [12 lines of output] + meson setup C:\Users\HP\AppData\Local\Temp\pip-install-6yi669d6\pandas_7817d26cb8064c2ab018f808557ac225 C:\Users\HP\AppData\Local\Temp\pip-install-6yi669d6\pandas_7817d26cb8064c2ab018f808557ac225\.mesonpy-7yo2u2mv\build -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --vsenv --native-file=C:\Users\HP\AppData\Local\Temp\pip-install-6yi669d6\pandas_7817d26cb8064c2ab018f808557ac225\.mesonpy-7yo2u2mv\build\meson-python-native-file.ini The Meson build system Version: 1.2.1 Source dir: C:\Users\HP\AppData\Local\Temp\pip-install-6yi669d6\pandas_7817d26cb8064c2ab018f808557ac225 Build dir: C:\Users\HP\AppData\Local\Temp\pip-install-6yi669d6\pandas_7817d26cb8064c2ab018f808557ac225\.mesonpy-7yo2u2mv\build Build type: native build Project name: pandas Project version: 2.1.4 ..\..\meson.build:2:0: ERROR: Could not parse vswhere.exe output A full log can be found at C:\Users\HP\AppData\Local\Temp\pip-install-6yi669d6\pandas_7817d26cb8064c2ab018f808557ac225\.mesonpy-7yo2u2mv\build\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.
解决方法
安装/修复Visual Studio构建工具
vswhere.exe是Visual Studio安装器的配套工具,meson依赖它查找C编译环境。确保已安装Visual Studio(社区版即可)或单独的Visual Studio Build Tools,并且勾选了**C构建工具**组件(包含MSVC编译器、Windows SDK等核心内容)。如果已安装,打开Visual Studio Installer选择「修改」或「修复」,确认组件完整。使用开发者命令提示符执行安装
打开对应版本的Visual Studio开发者命令提示符(比如「x64 Native Tools Command Prompt for VS 2022」),该环境已自动配置好编译所需的系统变量,直接在这个窗口运行pip install pandas即可绕过vswhere的解析问题。安装预编译的pandas轮子
跳过源码编译步骤,直接安装预编译的二进制包:pip install pandas --only-binary :all:此命令会强制pip下载预编译的
.whl文件,无需本地编译,彻底避免meson和vswhere的相关问题。检查vswhere.exe是否正常工作
找到vswhere.exe的默认路径:C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe,双击运行或在命令行执行,查看输出是否正常。如果输出乱码、为空或报错,说明Visual Studio安装存在问题,需要修复或重新安装。
内容的提问来源于stack exchange,提问作者Ysf_Baradi

