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

执行npm install electron时出现distutils缺失错误求助

修复Electron安装时node-gyp因Python3.12 distutils缺失的错误

以下是几个可行的解决方法:

方法1:安装distutils模块

Python 3.12默认移除了distutils,需手动补充:

  • Linux(Ubuntu/Debian):通过系统包管理器安装
    sudo apt-get install python3-distutils
    
    Fedora/RHEL系发行版:
    sudo dnf install python3-distutils
    
  • Windows/macOS:通过pip安装setuptools(distutils已整合到setuptools中)
    pip install setuptools
    

方法2:指定兼容的Python版本给node-gyp

node-gyp对Python3.12的支持尚不完善,可切换到3.11或更低版本:

  • 临时指定版本安装Electron:
    Windows命令行:
    set PYTHON=C:\path\to\python3.11.exe && npm install electron
    
    Linux/macOS:
    PYTHON=/usr/bin/python3.11 npm install electron
    
  • 全局配置node-gyp默认Python版本:
    npm config set python /path/to/python3.11
    
    配置完成后重新执行npm install electron

方法3:跳过可选依赖构建

如果gl是Electron的可选依赖,可尝试跳过可选依赖安装:

npm install electron --no-optional

额外注意事项

  • 更新node-gyp到最新版本:
    npm install -g node-gyp
    
  • 确保已安装对应系统的构建工具:Windows需安装Visual Studio Build Tools,macOS需安装Xcode Command Line Tools,Linux需安装gcc/g++等编译套件

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.07 10:06:03