执行pip install opencv-contrib-python遇DistutilsPlatformError错误求助
问题描述
执行pip install opencv-contrib-python命令时安装失败,核心报错信息为:
distutils.errors.DistutilsPlatformError: VC 6.0 is not supported by this module
完整报错日志:
Collecting opencv-contrib-python Using cached opencv-contrib-python-4.9.0.80.tar.gz (152.6 MB) Installing build dependencies ... error error: subprocess-exited-with-error pip subprocess to install build dependencies did not run successfully. exit code: 1 [86 lines of output] Ignoring numpy: markers 'python_version == "3.6" and platform_machine != "aarch64" and platform_machine != "arm64"' don't match your environment Ignoring numpy: markers 'python_version == "3.7" and platform_machine != "aarch64" and platform_machine != "arm64"' don't match your environment Ignoring numpy: markers 'python_version == "3.8" and platform_machine != "aarch64" and platform_machine != "arm64"' don't match your environment Ignoring numpy: markers 'python_version <= "3.9" and sys_platform == "linux" and platform_machine == "aarch64"' don't match your environment Ignoring numpy: markers 'python_version <= "3.9" and sys_platform == "darwin" and platform_machine == "arm64"' don't match your environment Ignoring numpy: markers 'python_version == "3.9" and platform_machine != "aarch64" and platform_machine != "arm64"' don't match your environment Ignoring numpy: markers 'python_version == "3.10" and platform_system != "Darwin"' don't match your environment Ignoring numpy: markers 'python_version == "3.10" and platform_system == "Darwin"' don't match your environment Collecting cmake>=3.1 Using cached cmake-3.28.1.tar.gz (42 kB) Installing build dependencies: started Installing build dependencies: finished with status 'done' Getting requirements to build wheel: started Getting requirements to build wheel: finished with status 'done' Preparing metadata (pyproject.toml): started Preparing metadata (pyproject.toml): finished with status 'done' Collecting numpy==1.22.2 Using cached numpy-1.22.2.zip (11.4 MB) Installing build dependencies: started Installing build dependencies: finished with status 'done' Getting requirements to build wheel: started Getting requirements to build wheel: finished with status 'error' error: subprocess-exited-with-error Getting requirements to build wheel did not run successfully. exit code: 1 [47 lines of output] Traceback (most recent call last): File "C:/msys64/mingw64/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module> main() File "C:/msys64/mingw64/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main json_out['return_val'] = hook(**hook_input['kwargs']) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:/msys64/mingw64/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 112, in get_requires_for_build_wheel backend = _build_backend() ^^^^^^^^^^^^^^^^ File "C:/msys64/mingw64/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 77, in _build_backend obj = import_module(mod_path) ^^^^^^^^^^^^^^^^^^^^^^^ File "C:/msys64/mingw64/lib/python3.11/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<frozen importlib._bootstrap>", line 1204, in _gcd_import File "<frozen importlib._bootstrap>", line 1176, in _find_and_load File "<frozen importlib._bootstrap>", line 1126, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "<frozen importlib._bootstrap>", line 1204, in _gcd_import File "<frozen importlib._bootstrap>", line 1176, in _find_and_load File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 690, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 944, in exec_module File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "C:/Users/bao15/AppData/Local/Temp/pip-build-env-37yuw_7d/overlay/lib/python3.11/site-packages/setuptools/__init__.py", line 242, in <module> monkey.patch_all() File "C:/Users/bao15/AppData/Local/Temp/pip-build-env-37yuw_7d/overlay/lib/python3.11/site-packages/setuptools/monkey.py", line 99, in patch_all patch_for_msvc_specialized_compiler() File "C:/Users/bao15/AppData/Local/Temp/pip-build-env-37yuw_7d/overlay/lib/python3.11/site-packages/setuptools/monkey.py", line 162, in patch_for_msvc_specialized_compiler patch_func(*msvc9('find_vcvarsall')) ^^^^^^^^^^^^^^^^^^^^^^^ File "C:/Users/bao15/AppData/Local/Temp/pip-build-env-37yuw_7d/overlay/lib/python3.11/site-packages/setuptools/monkey.py", line 149, in patch_params mod = import_module(mod_name) ^^^^^^^^^^^^^^^^^^^^^^^ File "C:/msys64/mingw64/lib/python3.11/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<frozen importlib._bootstrap>", line 1204, in _gcd_import File "<frozen importlib._bootstrap>", line 1176, in _find_and_load File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 690, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 944, in exec_module File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "C:/Users/bao15/AppData/Local/Temp/pip-build-env-37yuw_7d/overlay/lib/python3.11/site-packages/setuptools/_distutils/msvc9compiler.py", line 295, in <module> raise DistutilsPlatformError("VC %0.1f is not supported by this module" % VERSION) distutils.errors.DistutilsPlatformError: VC 6.0 is not supported by this module [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error Getting requirements to build wheel did not run successfully. exit code: 1 See above for output. note: This error originates from a subprocess, and is likely not a problem with pip. [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error pip subprocess to install build dependencies did not run successfully. exit code: 1 See above for output. note: This error originates from a subprocess, and is likely not a problem with pip.
原因分析
MSYS2环境中的Python在构建依赖包(如numpy)时,错误检测到系统中存在旧版本的VC 6.0编译器,而当前版本的setuptools/distutils不再支持VC 6.0,同时未正确识别并使用MSYS2自带的MinGW编译器。
解决方案
方法1:安装预编译二进制包(推荐)
跳过源码编译,直接安装预编译的兼容版本:
pip install opencv-contrib-python --only-binary :all:
也可以先安装适配Python 3.11的numpy版本,再安装opencv:
pip install numpy>=1.23 opencv-contrib-python
方法2:配置MSYS2使用MinGW编译器
- 打开MSYS2 MinGW 64-bit终端,安装必要的编译工具:
pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-python-pip mingw-w64-x86_64-python-numpy
- 设置环境变量,强制使用MinGW编译器:
export CC=gcc export CXX=g++ export DISTUTILS_USE_SDK=1 export MSSdk=1
如果需要永久生效,可将上述命令添加到~/.bashrc文件中。
3. 重新执行安装命令:
pip install opencv-contrib-python
方法3:临时移除VC 6.0相关环境变量
如果系统中存在VC 6.0的环境变量,临时移除后再安装:
unset INCLUDE unset LIB pip install opencv-contrib-python
内容的提问来源于stack exchange,提问作者Lucas2306
相关产品推荐
相关产品推荐

