You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows环境下安装pytrec_eval库失败的技术求助

解决Windows 10安装pytrec_eval时的VC++ 14.0依赖问题

针对你在Python 3.8.11和3.11.0环境下安装pytrec_eval时反复提示缺少Microsoft Visual C++ 14.0或更高版本的问题,以下是几个可行的解决办法:

1. 确认Microsoft C++ Build Tools安装完整组件

很多时候安装Build Tools时只选了默认选项,缺少编译所需的核心组件:

  • 打开Microsoft Visual Studio Installer,找到已安装的Microsoft C++ Build Tools
  • 勾选**Desktop development with C++**工作负载,确保包含以下子组件:
    • MSVC v142 - VS 2019 C++ x64/x86生成工具(或更高版本)
    • Windows 10 SDK(匹配你的系统版本)
    • C++ CMake工具 for Windows
  • 点击「修改」完成安装后,重启电脑再尝试安装pytrec_eval

2. 使用预编译wheel包跳过编译步骤

pytrec_eval需要编译C扩展,直接用预编译好的wheel包可以绕开环境依赖问题:

  • 先安装wheel工具:pip install wheel
  • 下载对应你Python版本和系统架构的pytrec_eval wheel文件(比如Python3.8 64位对应cp38-win_amd64,Python3.11对应cp311-win_amd64)
  • 执行本地安装:pip install pytrec_eval-0.5-cpXX-win_amd64.whl(替换XX为你的Python版本号,文件名以实际下载的为准)

3. 检查VC++工具链的环境变量

如果已安装正确组件但仍报错,可能是环境变量未配置:

  • 将VC++编译工具的路径添加到系统PATH中,示例路径(根据你的Build Tools版本调整):
    C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.37.32822\bin\Hostx64\x64
  • 关闭所有终端和IDE,重新打开后执行pip install pytrec_eval

附你提供的报错信息:

pip install pytrec_eval
Collecting pytrec_eval
  Using cached pytrec_eval-0.5.tar.gz (15 kB)
  Preparing metadata (setup.py) ... done
Installing collected packages: pytrec_eval
  DEPRECATION: pytrec_eval is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
  Running setup.py install for pytrec_eval ... error
  error: subprocess-exited-with-error
  
  × Running setup.py install for pytrec_eval did not run successfully.
  │ exit code: 1
  ╰─> [15 lines of output]
      Fetching trec_eval from https://github.com/usnistgov/trec_eval/archive/v9.0.8.tar.gz.
      C:\Users\c\AppData\Local\Programs\Python\Python311\Lib\site-packages\setuptools\dist.py:771: UserWarning: Usage of dash-separated 'description-file' will not be supported in future versions. Please use the underscore name 'description_file' instead
        warnings.warn(
      running install
      C:\Users\c\AppData\Local\Programs\Python\Python311\Lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
        warnings.warn(
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-cpython-311
      creating build\lib.win-amd64-cpython-311\pytrec_eval
      copying py\__init__.py -> build\lib.win-amd64-cpython-311\pytrec_eval
      running build_ext
      building 'pytrec_eval_ext' extension
      error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> pytrec_eval

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

内容的提问来源于stack exchange,提问作者Kcndze

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 16:20:28