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

node-gyp调用Python3报错:print语法缺失括号,求助排查

问题排查与解决:node-gyp Python语法报错

报错核心原因

你遇到的是node-gyp版本不兼容Python 3导致的语法错误:旧版node-gyp使用Python 2的print "xxx"语法,但你系统里安装的是Python 3.10,Python 3强制要求print必须带括号print("xxx"),因此触发SyntaxError。

解决方法

  • 临时指定Python版本(适用于已安装Python 2的情况)
    执行命令强制npm用Python 2运行node-gyp:

    npm install --python=python2.7
    

    或者全局配置默认Python版本:

    npm config set python python2.7
    
  • 升级node-gyp到支持Python 3的版本

    1. 全局更新node-gyp:
      npm install -g node-gyp@latest
      
    2. 清除npm缓存避免残留问题:
      npm cache clean --force
      
    3. 重新安装项目依赖:
      npm install
      
  • 配置Python 3适配node-gyp
    如果不想用Python 2,直接指定系统里的Python 3路径给npm:

    npm config set python C:\Python310\python.exe
    

    同时确保node-gyp是最新版,执行上面的全局升级命令即可。

额外提示

如果项目依赖里锁定了旧版node-gyp,可以修改package.json中的devDependencies,将node-gyp版本改为latest,再重新执行npm install。

内容的提问来源于stack exchange,提问作者Coding With Sheri

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 02:35:16