error: Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build Tools“

在window端的anaconda虚拟环境中,想要安装mmdet出现了这个问题,完整的错误如下所示:

Building wheels for collected packages: pycocotools
Building wheel for pycocotools (pyproject.toml) ... error
error: subprocess-exited-with-error
× Building wheel for pycocotools (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [16 lines of output]
running bdist_wheel
running build
running build_py
creating build
creating build\lib.win-amd64-cpython-37
creating build\lib.win-amd64-cpython-37\pycocotools
copying pycocotools\coco.py -> build\lib.win-amd64-cpython-37\pycocotools
copying pycocotools\cocoeval.py -> build\lib.win-amd64-cpython-37\pycocotools
copying pycocotools\mask.py -> build\lib.win-amd64-cpython-37\pycocotools
copying pycocotools_init_.py -> build\lib.win-amd64-cpython-37\pycocotools
running build_ext
cythoning pycocotools/_mask.pyx to pycocotools_mask.c
building 'pycocotools._mask' extension
C:\Users\Acer\AppData\Local\Temp\pip-build-env-4fck_2gn\overlay\Lib\site-packages\Cython\Compiler\Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: C:\Users\Acer\AppData\Local\Temp\pip-install-4hy59_ky\pycocotools_12df3f2b8c5940a39d3ddbdaa5df8c1b\pycocotools_mask.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
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: Failed building wheel for pycocotools
Failed to build pycocotools
ERROR: Could not build wheels for pycocotools, which is required to install pyproject.toml-based projects

大概就是安装mmdet时需要安装依赖pycocotools,这个是目标检测比较常见的一个工具包,然后安装这个依赖的过程中发生了错误。

问题的可能原因是没有安转Microsoft Visual C++的编译器,定位为error: Microsoft Visual C++ 14.0 or greater is required,那么现在需要的是安装一个Visual studio,为此,我安装了Visual Studio 2019的专业版本之后,随即即可正常安装pycocotools(也可以正常安装mmdet)

如下所示:

(openmmlab) C:\Users\Acer>mim install mmdet
D:\Anaconda3\envs\openmmlab\lib\site-packages_distutils_hack_init_.py:33: UserWarning: Setuptools is replacing distutils.
warnings.warn("Setuptools is replacing distutils.")
Looking in links: https://download.openmmlab.com/mmcv/dist/cu102/torch1.10.0/index.html
Collecting mmdet
Using cached mmdet-2.25.2-py3-none-any.whl (1.4 MB)
Collecting pycocotools
Using cached pycocotools-2.0.5.tar.gz (24 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: numpy in d:\anaconda3\envs\openmmlab\lib\site-packages (from mmdet) (1.21.6)
Collecting terminaltables
Using cached terminaltables-3.1.10-py2.py3-none-any.whl (15 kB)
Collecting matplotlib
Using cached matplotlib-3.5.3-cp37-cp37m-win_amd64.whl (7.2 MB)
Requirement already satisfied: six in d:\anaconda3\envs\openmmlab\lib\site-packages (from mmdet) (1.16.0)
Requirement already satisfied: mmcv-full>=1.3.17 in d:\anaconda3\envs\openmmlab\lib\site-packages (from mmdet) (1.6.2)
Requirement already satisfied: pyyaml in d:\anaconda3\envs\openmmlab\lib\site-packages (from mmcv-full>=1.3.17->mmdet) (6.0)
Requirement already satisfied: addict in d:\anaconda3\envs\openmmlab\lib\site-packages (from mmcv-full>=1.3.17->mmdet) (2.4.0)
Requirement already satisfied: regex in d:\anaconda3\envs\openmmlab\lib\site-packages (from mmcv-full>=1.3.17->mmdet) (2022.9.13)
Requirement already satisfied: Pillow in d:\anaconda3\envs\openmmlab\lib\site-packages (from mmcv-full>=1.3.17->mmdet) (9.2.0)
Requirement already satisfied: yapf in d:\anaconda3\envs\openmmlab\lib\site-packages (from mmcv-full>=1.3.17->mmdet) (0.32.0)
Requirement already satisfied: packaging in d:\anaconda3\envs\openmmlab\lib\site-packages (from mmcv-full>=1.3.17->mmdet) (21.3)
Collecting fonttools>=4.22.0
Using cached fonttools-4.37.4-py3-none-any.whl (960 kB)
Requirement already satisfied: python-dateutil>=2.7 in d:\anaconda3\envs\openmmlab\lib\site-packages (from matplotlib->mmdet) (2.8.2)
Requirement already satisfied: pyparsing>=2.2.1 in d:\anaconda3\envs\openmmlab\lib\site-packages (from matplotlib->mmdet) (3.0.9)
Collecting cycler>=0.10
Using cached cycler-0.11.0-py3-none-any.whl (6.4 kB)
Collecting kiwisolver>=1.0.1
Using cached kiwisolver-1.4.4-cp37-cp37m-win_amd64.whl (54 kB)
Requirement already satisfied: typing-extensions in d:\anaconda3\envs\openmmlab\lib\site-packages (from kiwisolver>=1.0.1->matplotlib->mmdet) (4.4.0)
Building wheels for collected packages: pycocotools
Building wheel for pycocotools (pyproject.toml) ... done
Created wheel for pycocotools: filename=pycocotools-2.0.5-cp37-cp37m-win_amd64.whl size=74562 sha256=cf3ea032d69b34bb03b6a7aa57dfdccefd5a4efe9b492c60c93febc553166c48
Stored in directory: c:\users\acer\appdata\local\pip\cache\wheels\85\c4\f0\7128093a134f590e4383fd60cb484960878721d98b9a515317
Successfully built pycocotools
Installing collected packages: terminaltables, kiwisolver, fonttools, cycler, matplotlib, pycocotools, mmdet
Successfully installed cycler-0.11.0 fonttools-4.37.4 kiwisolver-1.4.4 matplotlib-3.5.3 mmdet-2.25.2 pycocotools-2.0.5 terminaltables-3.1.10

Visual Studio 2019的安装,自行网上搜索即可。

在安装 `mmcv` 时,如果遇到错误提示 `error: Microsoft Visual C++ 14.0 or greater is required`,这表明系统中缺少必要的 Microsoft Visual C++ 编译工具链。`mmcv` 是一个基于 C++ 和 CUDA 的库,因此在 Windows 上安装时,往往需要依赖 Microsoft Visual C++ 的构建工具来编译扩展模块。 ### 错误原因 该错误的核心原因是系统缺少 Microsoft Visual C++ 14.0 或更高版本的构建工具链。Python 的 `setuptools` 在尝试编译 `mmcv` 的本地扩展模块时,会调用 Microsoft Visual C++ 编译器,如果没有正确安装或配置该编译器,就会抛出此错误[^3]。 ### 解决方法 #### 方法一:安装 Microsoft C++ Build Tools 根据错误提示,最直接的解决方式是安装 [Microsoft C++ Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/)。下载后,在安装过程中选择以下组件: - **MSVC v140 - v143 C++ x64/x86 Build Tools** - **Windows SDK** 安装完成后,重启命令行工具并重新运行 `pip install mmcv` 命令。 #### 方法二:使用预编译的 mmcv 版本 为了绕过本地编译过程,可以直接安装官方提供的预编译版本。推荐使用以下命令安装: ```bash pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/index.html ``` 该命令会从 OpenMMLab 提供的镜像站点下载适用于当前系统环境的预编译包,从而避免对 Visual C++ 编译器的依赖[^2]。 #### 方法三:使用虚拟环境或容器 如果目标系统无法安装 Visual C++ 构建工具,或者希望避免对系统全局环境的修改,可以使用虚拟环境(如 `conda`)或容器技术(如 Docker)来隔离依赖。 例如,使用 `conda` 安装 `mmcv`: ```bash conda install -c conda-forge mmcv ``` 这种方式会自动处理所有依赖项,包括 C++ 编译器需求[^4]。 #### 方法四:手动配置环境变量 在某些情况下,系统可能已经安装了 Microsoft Visual C++ Build Tools,但 Python 无法识别。此时可以尝试手动设置环境变量,确保 Python 能够找到编译器路径。例如,设置 `VSINSTALLDIR` 指向 Visual Studio 的安装目录,并将 `VC\Tools\MSVC\bin\Hostx64\x64` 添加到 `PATH` 环境变量中[^1]。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Clichong

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值