解决服务器默认python是2.4导致无法编译模块的问题
发布于 3年前 作者 fengmk2 3248 次浏览 最后一次编辑是 5个月前 来自 分享

例如需要安装 microtime :

$ npm install microtime

提示语法错误:

> node-gyp rebuild

info it worked if it ends with ok 
spawn python [ '/home/admin/.node-gyp/0.6.17/tools/gyp_addon',
  'binding.gyp',
  '-I/home/admin/node_modules/microtime/build/config.gypi',
  '-f',
  'make' ]
Traceback (most recent call last):
  File "/home/admin/.node-gyp/0.6.17/tools/gyp_addon", line 14, in ?
    import gyp
  File "/home/admin/.node-gyp/0.6.17/tools/gyp/pylib/gyp/__init__.py", line 8, in ?
    import gyp.input
  File "/home/admin/.node-gyp/0.6.17/tools/gyp/pylib/gyp/input.py", line 14, in ?
    import gyp.common
  File "/home/admin/.node-gyp/0.6.17/tools/gyp/pylib/gyp/common.py", line 373
    with open(source_path) as source_file:
            ^
SyntaxError: invalid syntax
ERR! Error: `gyp_addon` failed with exit code: 1
    at ChildProcess.onCpExit (/opt/taobao/install/node.js/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:226:16)
    at ChildProcess.emit (events.js:70:17)
    at maybeExit (child_process.js:362:16)
    at Process.onexit (child_process.js:398:5)
ERR! not ok

很明显,python2.4不支持 with 语法。 那么安装python2.6咯,然后又发现pe不让修改默认的python为python2.6,怎么办呢? 在运行npm的时候设置临时 PYTHON 环境变量就好了。

$ PYTHON=`which python2.6` npm install microtime

oh yeah, 解决问题。

2 回复

这是啥意思?

学习之, PYTHON=which python2.6 npm install 设置临时环境变量

回到顶部