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

Windows11虚拟环境安装Python库遇subprocess-exited-with-error求助

问题描述

Windows11笔记本上安装了Python3.10和3.11两个版本,使用VS Code的Git Bash终端创建venv虚拟环境后,执行pip install numpy时出现subprocess-exited-with-error错误,报错提示VC 6.0不被该模块支持。另外,未使用虚拟环境时,用pip或pip3安装库后运行文件,会提示库未找到。自安装Mingw后就未使用Python,怀疑该工具是问题诱因,尝试过python3 -m pip install numpy、python -m pip install numpy等命令均无法解决。

终端报错信息

my_pc  MINGW64 ~/OneDrive/Documents/Trading/interviews
$ python -m venv venv
my_pc  MINGW64 ~/OneDrive/Documents/Trading/interviews
$ source venv/bin/activate
(venv) 
my_pc  MINGW64 ~/OneDrive/Documents/Trading/interviews
$ which python
/c/Users/my_pc/OneDrive/Documents/Trading/interviews/venv/bin/python
(venv) 
my_pc  MINGW64 ~/OneDrive/Documents/Trading/interviews
$ pip --version
pip 22.3.1 from C:/Users/my_pc/OneDrive/Documents/Trading/interviews/venv/lib/python3.10/site-packages/pip (python 3.10)
(venv) 
my_pc MINGW64 ~/OneDrive/Documents/Trading/interviews
$ pip install numpy
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))': /simple/numpy/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))': /simple/numpy/
Collecting numpy
  Using cached numpy-1.24.2.tar.gz (10.9 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [40 lines of output]
      Traceback (most recent call last):
        File "C:\Users\my_pc\OneDrive\Documents\Trading\interviews\venv\lib\python3.10\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
          main()
        File "C:\Users\my_pc\OneDrive\Documents\Trading\interviews\venv\lib\python3.10\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:\Users\my_pc\OneDrive\Documents\Trading\interviews\venv\lib\python3.10\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 112, in get_requires_for_build_wheel
          backend = _build_backend()
        File "C:\Users\my_pc\OneDrive\Documents\Trading\interviews\venv\lib\python3.10\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.10/importlib/__init__.py", line 126, in import_module
          return _bootstrap._gcd_import(name[level:], package, level)
        File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
        File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
        File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
        File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
        File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
        File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
        File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
        File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
        File "<frozen importlib._bootstrap_external>", line 887, in exec_module
        File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
        File "C:/Users/my_pc/AppData/Local/Temp/pip-build-env-ocqvaqmi/overlay/lib/python3.10/site-packages/setuptools/__init__.py", line 242, in <module>    
          monkey.patch_all()
        File "C:/Users/my_pc/AppData/Local/Temp/pip-build-env-ocqvaqmi/overlay/lib/python3.10/site-packages/setuptools/monkey.py", line 99, in patch_all      
          patch_for_msvc_specialized_compiler()
        File "C:/Users/my_pc/AppData/Local/Temp/pip-build-env-ocqvaqmi/overlay/lib/python3.10/site-packages/setuptools/monkey.py", line 162, in patch_for_msvc_specialized_compiler
          patch_func(*msvc9('find_vcvarsall'))
        File "C:/Users/my_pc/AppData/Local/Temp/pip-build-env-ocqvaqmi/overlay/lib/python3.10/site-packages/setuptools/monkey.py", line 149, in patch_params  
          mod = import_module(mod_name)
        File "C:/msys64/mingw64/lib/python3.10/importlib/__init__.py", line 126, in import_module
          return _bootstrap._gcd_import(name[level:], package, level)
        File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
        File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
        File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
        File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
        File "<frozen importlib._bootstrap_external>", line 887, in exec_module
        File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
        File "C:/Users/ndamb/AppData/Local/Temp/pip-build-env-ocqvaqmi/overlay/lib/python3.10/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.

修复方案

  • 使用预编译包跳过编译:直接从国内镜像安装numpy的预编译wheels包,避免触发编译流程,同时解决网络问题。执行以下命令:

    pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple
    
  • 移除Mingw环境干扰:

    1. 打开系统「环境变量」设置,检查PATH变量中是否包含Mingw相关路径(如C:/msys64/mingw64/bin),将其移至Python路径之后,或者暂时删除该路径。
    2. 重启Git Bash终端,激活虚拟环境后,执行which python确认使用的是虚拟环境内的官方Python解释器,而非Mingw自带的Python。
  • 修复全局Python库找不到问题:

    1. 使用版本指定的pip命令安装库,避免版本混淆:给Python3.10安装库用py -3.10 -m pip install 库名,给Python3.11安装用py -3.11 -m pip install 库名。
    2. 在VS Code中,点击左下角状态栏的Python版本,切换到对应全局Python环境,确保运行代码时使用的解释器与安装库的一致。
  • 安装VC编译工具(备选):如果必须编译安装,下载并安装微软官方的Visual C++ Build Tools,勾选「Desktop development with C++」组件,安装完成后重启终端再尝试安装numpy。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 06:05:03