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

使用pip安装requirements.txt时出现numpy模块安装错误求助

问题描述

在Windows10系统的Python3.11环境下执行pip install -r requirements.txt时安装失败,错误日志如下:

Collecting websockets==8.1
  Using cached websockets-8.1.tar.gz (58 kB)
  Preparing metadata (setup.py) ... done
Collecting tqdm==4.31.1
  Using cached tqdm-4.31.1-py2.py3-none-any.whl (48 kB)
Collecting pandas==1.1.2
  Using cached pandas-1.1.2.tar.gz (5.2 MB)
  Installing build dependencies ... error
  error: subprocess-exited-with-error

  × pip subprocess to install build dependencies did not run successfully.
  │ exit code: 1
  ╰─> [315 lines of output]
      Ignoring numpy: markers 'python_version == "3.6" and platform_system != "AIX"' don't match your environment
      Ignoring numpy: markers 'python_version == "3.7" and platform_system != "AIX"' don't match your environment
      Ignoring numpy: markers 'python_version == "3.6" and platform_system == "AIX"' don't match your environment
      Ignoring numpy: markers 'python_version == "3.7" and platform_system == "AIX"' don't match your environment
      Ignoring numpy: markers 'python_version >= "3.8" and platform_system == "AIX"' don't match your environment
      Collecting setuptools
        Using cached setuptools-65.5.1-py3-none-any.whl (1.2 MB)
      Collecting wheel
        Using cached wheel-0.38.2-py3-none-any.whl (36 kB)
      Collecting Cython<3,>=0.29.16
        Using cached Cython-0.29.32-py2.py3-none-any.whl (986 kB)
      Collecting numpy==1.17.3
        Using cached numpy-1.17.3.zip (6.4 MB)
        Preparing metadata (setup.py): started
        Preparing metadata (setup.py): finished with status 'done'
      Installing collected packages: wheel, setuptools, numpy, Cython
        DEPRECATION: numpy is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
        Running setup.py install for numpy: started
        Running setup.py install for numpy: finished with status 'error'
        error: subprocess-exited-with-error

        Running setup.py install for numpy did not run successfully.
        exit code: 1

        [279 lines of output]
        Running from numpy source directory.

        Note: if you need reliable uninstall behavior, then install
        with pip instead of using `setup.py install`:

          - `pip install .`       (from a git repo or downloaded source
                                   release)
          - `pip install numpy`   (last NumPy release on PyPi)


        blas_opt_info:
        blas_mkl_info:
        No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
        customize MSVCCompiler
          libraries mkl_rt not found in ['C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python311\\lib', 'C:\\', 'C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python311\\libs']
          NOT AVAILABLE

        blis_info:
        No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
        customize MSVCCompiler
          libraries blis not found in ['C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python311\\lib', 'C:\\', 'C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python311\\libs']
          NOT AVAILABLE

        openblas_info:
        No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
        customize MSVCCompiler
        No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
        customize MSVCCompiler
          libraries openblas not found in ['C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python311\\lib', 'C:\\', 'C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python311\\libs']
        get_default_fcompiler: matching types: '['gnu', 'intelv', 'absoft', 'compaqv', 'intelev', 'gnu95', 'g95', 'intelvem', 'intelem', 'flang']'
        customize GnuFCompiler
        Could not locate executable g77
        Could not locate executable f77
        customize IntelVisualFCompiler
(...)
        atlas_3_10_blas_threads_info:
        Setting PTATLAS=ATLAS
        No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
        customize MSVCCompiler
          libraries tatlas not found in ['C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python311\\lib', 'C:\\', 'C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python311\\libs']
          NOT AVAILABLE
(...)

  × pip subprocess to install build dependencies did not run successfully.
  │ exit code: 1
  ╰─> [315 lines of output]
      Ignoring numpy: markers 'python_version == "3.6" and platform_system != "AIX"' don't match your environment
      Ignoring numpy: markers 'python_version == "3.7" and platform_system != "AIX"' don't match your environment
      Ignoring numpy: markers 'python_version == "3.6" and platform_system == "AIX"' don't match your environment
      Ignoring numpy: markers 'python_version == "3.7" and platform_system == "AIX"' don't match your environment
      Ignoring numpy: markers 'python_version >= "3.8" and platform_system == "AIX"' don't match your environment
      Collecting setuptools
        Using cached setuptools-65.5.1-py3-none-any.whl (1.2 MB)
      Collecting wheel
        Using cached wheel-0.38.2-py3-none-any.whl (36 kB)
      Collecting Cython<3,>=0.29.16
        Using cached Cython-0.29.32-py2.py3-none-any.whl (986 kB)
      Collecting numpy==1.17.3
        Using cached numpy-1.17.3.zip (6.4 MB)
        Preparing metadata (setup.py): started
        Preparing metadata (setup.py): finished with status 'done'
      Installing collected packages: wheel, setuptools, numpy, Cython
        DEPRECATION: numpy is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
        Running setup.py install for numpy: started
        Running setup.py install for numpy: finished with status 'error'
        error: subprocess-exited-with-error

        Running setup.py install for numpy did not run successfully.
        exit code: 1

        [279 lines of output]
        Running from numpy source directory.

        Note: if you need reliable uninstall behavior, then install
        with pip instead of using `setup.py install`:

          - `pip install .`       (from a git repo or downloaded source
                                   release)
          - `pip install numpy`   (last NumPy release on PyPi)


        blas_opt_info:
        blas_mkl_info:
        No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
        customize MSVCCompiler
          libraries mkl_rt not found in ['C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python311\\lib', 'C:\\', 'C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python311\\libs']
          NOT AVAILABLE

        blis_info:
        No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
        customize MSVCCompiler
          libraries blis not found in ['C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python311\\lib', 'C:\\', 'C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python311\\libs']
          NOT AVAILABLE

        openblas_info:
        No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
        customize MSVCCompiler
        No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
        customize MSVCCompiler
          libraries openblas not found in ['C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python311\\lib', 'C:\\', 'C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python311\\libs']
        get_default_fcompiler: matching types: '['gnu', 'intelv', 'absoft', 'compaqv', 'intelev', 'gnu95', 'g95', 'intelvem', 'intelem', 'flang']'
        customize GnuFCompiler
        Could not locate executable g77
        Could not locate executable f77
        customize IntelVisualFCompiler
(...)
        C:\Users\user\AppData\Local\Temp\pip-install-q6qg404u\numpy_4eb1db888ba3499b83b89bb3bed687e2\numpy\distutils\system_info.py:690: UserWarning:
            Blas (http://www.netlib.org/blas/) libraries not found.
            Directories to search for the libraries can be specified in the
            numpy/distutils/site.cfg file (section [blas]) or by setting
            the BLAS environment variable.
          self.calc_info()
        blas_src_info:
          NOT AVAILABLE

        openblas_lapack_info:
        No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
        customize MSVCCompiler
        No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
        customize MSVCCompiler
          libraries openblas not found in ['C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python311\\lib', 'C:\\', 'C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python311\\libs']
          NOT AVAILABLE
(...)

        C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\setuptools\_distutils\dist.py:264: UserWarning: Unknown distribution option: 'define_macros'
          warnings.warn(msg)
        running install
        C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
          warnings.warn(
        running build
        running config_cc
        unifing config_cc, config, build_clib, build_ext, build commands --compiler options
        running config_fc
        unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
        running build_src
        build_src
        building py_modules sources
        creating build
        creating build\src.win-amd64-3.1
        creating build\src.win-amd64-3.1\numpy
        creating build\src.win-amd64-3.1\numpy\distutils
        building library "npymath" sources
        No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
        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: legacy-install-failure

      Encountered error while trying to install package.

      numpy

      note: This is an issue with the package mentioned above, not pip.
      hint: See above for output from the failure.
      [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.
原因分析
  1. 版本不兼容:numpy==1.17.3和pandas==1.1.2都是2019年的老版本,完全不支持2022年发布的Python3.11,pip无法找到适配的预编译wheel包,只能尝试从源码编译。
  2. 缺少编译工具:源码编译需要Microsoft Visual C++ 14.0及以上版本的编译环境,当前系统未安装,导致编译失败。
解决方案

方案一:升级依赖版本(推荐)

修改requirements.txt中的包版本为支持Python3.11的兼容版本,示例:

websockets>=8.1,<12  # 8.1本身兼容3.11,也可以直接用最新版
tqdm>=4.31.1         # 老版本兼容,也可升级
numpy>=1.23.5        # 第一个支持Python3.11的numpy版本
pandas>=1.5.3        # 第一个支持Python3.11的pandas版本

修改后重新执行:

pip install -r requirements.txt

方案二:降级Python版本

如果必须使用原requirements.txt中的老版本,将Python降级到3.7或3.8(numpy1.17.3仅支持Python3.5~3.8),安装对应版本后重新执行pip install -r requirements.txt,此时会直接下载预编译wheel包,无需编译。

方案三:安装编译工具(不推荐)

下载安装Microsoft Visual C++ Build Tools,勾选"Desktop development with C++"组件完成安装,重启终端后重新执行pip install -r requirements.txt。但老版本numpy/pandas在Python3.11下可能存在未知兼容性问题,不建议采用此方案。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 15:31:02