RuntimeError: The detected CUDA version (12.0) mismatches the version that was used to compile PyTorch (11.8). Please make sure to use the same CUDA versions.

Author: yysturdyCreated Feb 2, 2026Updated Feb 2, 2026

python setup.py build develop D:\aaaa\anconda\envs\grounding-dino\lib\site-packages\torch\\utils\cpp_extension.py:25: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81. from pkg_resources import packaging # type: ignore[attr-defined] fatal: not a git repository (or any of the parent directories): .git Building wheel groundingdino-0.1.0 Compiling with CUDA running build running build_py copying groundingdino\version.py -> build\lib.win-amd64-cpython-39\groundingdino running build_ext D:\aaaa\anconda\envs\grounding-dino\lib\site-packages\torch\\utils\cpp_extension.py:476: UserWarning: Attempted to use ninja as the BuildExtension backend but we could not find ninja.. Falling back to using the slow distutils backend. warnings.warn(msg.format('we could not find ninja.')) D:\aaaa\anconda\envs\grounding-dino\lib\site-packages\torch\\utils\cpp_extension.py:359: UserWarning: Error checking compiler version for cl: [WinError 2] 系统找不到指定的文件。 warnings.warn(f'Error checking compiler version for {compiler}: {error}') Traceback (most recent call last): File "D:\小目标检测\GroundingDINO-main\setup.py", line 204, in setup( File "C:\Users\aaaa\AppData\Roaming\Python\Python39\site-packages\setuptools_init_.py", line 115, in setup return distutils.core.setup(**attrs) File "C:\Users\aaaa\AppData\Roaming\Python\Python39\site-packages\setuptools_distutils\core.py", line 186, in setup return run_commands(dist) File "C:\Users\aaaa\AppData\Roaming\Python\Python39\site-packages\setuptools_distutils\core.py", line 202, in run_commands dist.run_commands() File "C:\Users\aaaa\AppData\Roaming\Python\Python39\site-packages\setuptools_distutils\dist.py", line 1002, in run_commands self.run_command(cmd) File "C:\Users\aaaa\AppData\Roaming\Python\Python39\site-packages\setuptools\dist.py", line 1102, in run_command super().run_command(command) File "C:\Users\aaaa\AppData\Roaming\Python\Python39\site-packages\setuptools_distutils\dist.py", line 1021, in run_command cmd_obj.run() File "C:\Users\aaaa\AppData\Roaming\Python\Python39\site-packages\setuptools_distutils\command\build.py", line 135, in run self.run_command(cmd_name) File "C:\Users\aaaa\AppData\Roaming\Python\Python39\site-packages\setuptools_distutils\cmd.py", line 357, in run_command self.distribution.run_command(command) File "C:\Users\aaaa\AppData\Roaming\Python\Python39\site-packages\setuptools\dist.py", line 1102, in run_command super().run_command(command) File "C:\Users\aaaa\AppData\Roaming\Python\Python39\site-packages\setuptools_distutils\dist.py", line 1021, in run_command cmd_obj.run() File "C:\Users\aaaa\AppData\Roaming\Python\Python39\site-packages\setuptools\command\build_ext.py", line 96, in run _build_ext.run(self) File "C:\Users\aaaa\AppData\Roaming\Python\Python39\site-packages\setuptools_distutils\command\build_ext.py", line 368, in run self.build_extensions() File "D:\aaaa\anconda\envs\grounding-dino\lib\site-packages\torch\\utils\cpp_extension.py", line 499, in build_extensions _check_cuda_version(compiler_name, compiler_version) File "D:\aaaa\anconda\envs\grounding-dino\lib\site-packages\torch\\utils\cpp_extension.py", line 387, in _check_cuda_version raise RuntimeError(CUDA_MISMATCH_MESSAGE.format(cuda_str_version, torch.version.cuda)) RuntimeError: The detected CUDA version (12.0) mismatches the version that was used to compile PyTorch (11.8). Please make sure to use the same CUDA versions.

I created a virtual environment using conda, and the torch installed corresponds to CUDA 11.8 version 2.0.1. However, my local CUDA Toolkit is version 12.0. What is the cause of this error? When running python setup.py build develop, the torch in the conda-created virtual environment must correspond to version 12.0.?

Source: IDEA-Research/GroundingDINO