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

Windows 10下CMD安装ONNX库失败:CMake编译报错求助

解决Windows 10 CMD中pip install onnx的CMake编译错误

你碰到的问题核心是普通CMD环境没加载Visual Studio的C/C++编译工具链,CMake找不到cl.exe编译器才会报错。下面给你两种靠谱的解决办法:

方法一:直接装预编译包(推荐,不用折腾编译)

跳过本地编译,直接用官方提供的现成二进制包安装,省心又快捷:

  • 打开CMD或者PowerShell,执行这条命令:
    pip install onnx --find-links=https://download.pytorch.org/whl/torch_stable.html
    
  • 要是你用conda环境,也可以这么装:
    conda install -c conda-forge onnx
    

方法二:配置VS编译环境后再安装

如果一定要本地编译安装,得先把VS的编译环境配置好:

  1. 在开始菜单里搜「Developer Command Prompt for VSxxxx」(xxxx是你的VS版本,比如2019/2022)
  2. 打开这个命令提示符,它会自动把cl.exe等编译工具的环境变量配置好
  3. 接着在这个窗口里重新执行pip install onnx就行

你遇到的完整错误日志:

ERROR: Command errored out with exit status 1:
 >>command: 'c:\users\realm\appdata\local\programs\python\python38-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\realm\AppData\Local\Temp\pip-install-oxwi8385\onnx\setup.py'"'"'; __file__='"'"'C:\Users\realm\AppData\Local\Temp\pip-install-oxwi8385\onnx\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\realm\AppData\Local\Temp\pip-record-h01e7u49\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\realm\appdata\local\programs\python\python38-32\Include\onnx'
cwd: C:\Users\realm\AppData\Local\Temp\pip-install-oxwi8385\onnx\
Complete output (82 lines):
running install
running build
running build_py
running create_version
running cmake_build
-- Building for: NMake Makefiles
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:17 (project):
  The CMAKE_C_COMPILER: cl is not a full path and was not found in the PATH.

  To use the NMake generator with Visual C++, cmake must be run from a shell
  that can use the compiler cl from the command line.  This environment is
  unable to invoke the cl compiler.

  To fix this problem, run cmake from the Visual Studio Command Prompt
  (vcvarsall.bat).

  Tell CMake where to find the compiler by setting either the environment
  variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
  the compiler, or to the compiler name if it is in the PATH.


CMake Error at CMakeLists.txt:17 (project):
  The CMAKE_CXX_COMPILER: cl is not a full path and was not found in the PATH.

  To use the NMake generator with Visual C++, cmake must be run from a shell
  that can use the compiler cl from the command line.  This environment is
  unable to invoke the cl compiler.

  To fix this problem, run cmake from the Visual Studio Command Prompt
  (vcvarsall.bat).

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path to
  the compiler, or to the compiler name if it is in the PATH.


> -- Configuring incomplete, errors occurred!
See also "C:/Users/realm/AppData/Local/Temp/pip-install-oxwi8385/onnx/.setuptools-cmake-build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/realm/AppData/Local/Temp/pip-install-oxwi8385/onnx/.setuptools-cmake-build/CMakeFiles/CMakeError.log".
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\realm\AppData\Local\Temp\pip-install-oxwi8385\onnx\setup.py", line 315, in <module>
    setuptools.setup(
  File "c:\users\realm\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\__init__.py", line 145, in setup
    return distutils.core.setup(**attrs)
  File "c:\users\realm\appdata\local\programs\python\python38-32\lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "c:\users\realm\appdata\local\programs\python\python38-32\lib\distutils\dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "c:\users\realm\appdata\local\programs\python\python38-32\lib\distutils\dist.py", line 985, in run_command
    cmd_obj.run()
  File "c:\users\realm\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\command\install.py", line 61, in run
    return orig.install.run(self)
  File "c:\users\realm\appdata\local\programs\python\python38-32\lib\distutils\command\install.py", line 545, in run
    self.run_command('build')
  File "c:\users\realm\appdata\local\programs\python\python38-32\lib\distutils\cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "c:\users\realm\appdata\local\programs\python\python38-32\lib\distutils\dist.py", line 985, in run_command
    cmd_obj.run()
  File "c:\users\realm\appdata\local\programs\python\python38-32\lib\distutils\command\build.py", line 135, in run
    self.run_command(cmd_name)
  File "c:\users\realm\appdata\local\programs\python\python38-32\lib\distutils\cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "c:\users\realm\appdata\local\programs\python\python38-32\lib\distutils\dist.py", line 985, in run_command
    cmd_obj.run()
  File "C:\Users\realm\AppData\Local\Temp\pip-install-oxwi8385\onnx\setup.py", line 209, in run
    self.run_command('cmake_build')
  File "c:\users\realm\appdata\local\programs\python\python38-32\lib\distutils\cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "c:\users\realm\appdata\local\programs\python\python38-32\lib\distutils\dist.py", line 985, in run_command
    cmd_obj.run()
  File "C:\Users\realm\AppData\Local\Temp\pip-install-oxwi8385\onnx\setup.py", line 195, in run
    subprocess.check_call(cmake_args)
  File "c:\users\realm\appdata\local\programs\python\python38-32\lib\subprocess.py", line 364, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['C:\Users\realm\AppData\Local\Programs\Python\Python38-32\Scripts\cmake.exe', '-DPYTHON_INCLUDE_DIR=c:\users\realm\appdata\local\programs\python\python38-32\include', '-DPYTHON_EXECUTABLE=c:\users\realm\appdata\local\programs\python\python38-32\python.exe', '-DBUILD_ONNX_PYTHON=ON', '-DCMAKE_EXPORT_COMPILE_COMMANDS=ON', '-DONNX_NAMESPACE=onnx', '-DPY_EXT_SUFFIX=.cp38-win32.pyd', '-DCMAKE_BUILD_TYPE=Release', '-DPY_VERSION=3.8', '-DONNX_USE_MSVC_STATIC_RUNTIME=ON', '-DONNX_ML=1', 'C:\Users\realm\AppData\Local\Temp\pip-install-oxwi8385\onnx']' returned non-zero exit status 1.
----------------------------------------
ERROR: Command errored out with exit status 1:
 >>'c:\users\realm\appdata\local\programs\python\python38-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\realm\AppData\Local\Temp\pip-install-oxwi8385\onnx\setup.py'"'"'; __file__='"'"'C:\Users\realm\AppData\Local\Temp\pip-install-oxwi8385\onnx\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\realm\AppData\Local\Temp\pip-record-h01e7u49\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\realm\appdata\local\programs\python\python38-32\Include\onnx'
Check the logs for full command output.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.07 10:47:29