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

PyCharm终端安装NumPy失败报错,CMD安装正常求助

PyCharm虚拟环境安装Numpy失败(CMake/ninja编译问题)

问题详情

项目路径:D:\PycharmProjects
在PyCharm虚拟环境终端执行pip install numpy时出现后端依赖安装失败,核心报错为编译ninja时提示CMake安装异常,但在系统CMD中可正常安装Numpy。完整报错信息如下:

(venv) PS D:\\PycharmProjects> pip install numpy
Collecting numpy
Downloading numpy-1.26.4.tar.gz (15.8 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 15.8/15.8 MB 5.5 MB/s eta 0:00:00
Installing build dependencies ... done
Getting requirements to build wheel ... done
Installing backend dependencies ... error
error: subprocess-exited-with-error

× pip subprocess to install backend dependencies did not run successfully.
│ exit code: 1
╰─> [36 lines of output]
Collecting ninja>=1.8.2
Using cached ninja-1.11.1.1.tar.gz (132 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'
Building wheels for collected packages: ninja
Building wheel for ninja (pyproject.toml): started
Building wheel for ninja (pyproject.toml): finished with status 'error'
error: subprocess-exited-with-error

            Building wheel for ninja (pyproject.toml) did not run successfully.
            exit code: 1
    
            [13 lines of output]
            C:\Users\User\AppData\Local\Temp\pip-build-env-cay87x7e\overlay\lib\python3.10\site-packages\setuptools_scm\git.py:308: UserWarning: git archive did not support describe output
          warnings.warn("git archive did not support describe output")
        C:\Users\User\AppData\Local\Temp\pip-build-env-cay87x7e\overlay\lib\python3.10\site-packages\setuptools_scm\git.py:327: UserWarning: unprocessed git archival found (no export subst applied)
          warnings.warn("unprocessed git archival found (no export subst applied)")
        Traceback (most recent call last):
          File "C:\Users\User\AppData\Local\Temp\pip-build-env-cay87x7e\overlay\lib\python3.10\site-packages\skbuild\setuptools_wrap.py", line 645, in setup
            cmkr = cmaker.CMaker(cmake_executable)
          File "C:\Users\User\AppData\Local\Temp\pip-build-env-cay87x7e\overlay\lib\python3.10\site-packages\skbuild\cmaker.py", line 148, in __init__
            self.cmake_version = get_cmake_version(self.cmake_executable)
          File "C:\Users\User\AppData\Local\Temp\pip-build-env-cay87x7e\overlay\lib\python3.10\site-packages\skbuild\cmaker.py", line 105, in get_cmake_version
            raise SKBuildError(msg) from err
    
        Problem with the CMake installation, aborting build. CMake executable is cmake
        [end of output]
    
        note: This error originates from a subprocess, and is likely not a problem with pip.
        ERROR: Failed building wheel for ninja
      Failed to build ninja
      ERROR: Could not build wheels for ninja, which is required to install pyproject.toml-based projects
      [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 backend 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.

解决方案

  • 强制使用预编译二进制包
    执行命令跳过本地编译,直接安装预编译好的Numpy:

    pip install numpy --only-binary :all:
    
  • 修复虚拟环境的CMake路径

    1. 在PyCharm虚拟环境终端输入cmake --version,若提示找不到命令,说明虚拟环境未继承系统PATH中的CMake路径
    2. 手动添加CMake路径(替换为你的实际安装路径):
      $env:Path += ";C:\Program Files\CMake\bin"
      
      添加完成后重新执行pip install numpy
  • 升级pip及构建工具
    先更新pip、setuptools和wheel到最新版本,再尝试安装:

    pip install --upgrade pip setuptools wheel
    pip install numpy
    
  • 复制系统环境已安装的Numpy到虚拟环境

    1. 找到系统Python的site-packages目录(例如C:\Python310\Lib\site-packages)
    2. 复制其中的numpy文件夹和numpy-*.dist-info文件夹到虚拟环境的site-packages目录(D:\PycharmProjects\venv\Lib\site-packages)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 19:50:30