【问题标题】:compile node.js appear "NameError: global name 'file' is not defined"编译node.js出现“NameError: global name 'file' is not defined”
【发布时间】:2013-03-22 13:12:04
【问题描述】:

我有 python2 和 python3,我运行 ./configure 并且它可以工作。但是我运行 make,

make -C out BUILDTYPE=Release V=1 make[1]: 进入目录`/home/colin4124/MyProgram/node/out' LD_LIBRARY_PATH=/home/colin4124/MyProgram/node/out/Release/lib.host:/home/colin4124/MyProgra>m/node/out/Release/lib.target:$LD_LIBRARY_PATH;导出 LD_LIBRARY_PATH; cd ../deps/v8/tools/gyp; mkdir -p /home/colin4124/MyProgram/node/out/Release/obj/gen; python ../../tools/gen-postmortem-metadata.py "/home/colin4124/MyProgram/node/out/Release/obj/gen/debug-support.cc" ../../src/objects. h ../../src/objects-inl.h 回溯(最近一次通话最后): 文件“../../tools/gen-postmortem-metadata.py”,第 479 行,在 发射配置(); 文件“../../tools/gen-postmortem-metadata.py”,第 432 行,在 emit_config 中 out = file(sys.argv[1], 'w'); NameError:未定义全局名称“文件” make[1]: *** [/home/colin4124/MyProgram/node/out/Release/obj/gen/debug-support.cc] 错误 1 make[1]: 离开目录`/home/colin4124/MyProgram/node/out' make: *** [节点] 错误 2

我怎么能解决它,想想你!!

【问题讨论】:

标签: node.js


【解决方案1】:

您的默认 Python 似乎是 3.x,但 Node 构建脚本需要 Python 2.x。

根据these instructions,您可以通过将PYTHON 环境变量设置为指向您的Python 2 可执行文件来修复它:

export PYTHON=`which python2`

【讨论】:

  • 确保运行 make distclean 以开始新的构建。此外,它假定您的 Python 2.x 可执行文件名为 python2,这在您的设置中可能有所不同。
  • 我不这么认为。因为我将python2设置为python,这意味着当我运行python时,它会运行python2
  • file() not being defined 表明该脚本正在使用 Python 3 运行。
  • 我已经按照你的方法设置了,但是脚本仍然在用 Python 3 运行,接下来我该怎么做?
  • python -V 说什么?如果它说它是 Python 2.x,也许尝试完全删除 Node 源目录并解压缩源存档以重新开始。
【解决方案2】:

这是因为您的默认pythonpython3.x。 Node.js 推荐python2.6/python2.7 编译源码。
尝试通过以下方式检查您的python 命令:

ls -l /usr/bin/python

它将显示lrwxrwxrwx 1 root root 9 Apr 3 15:46 /usr/bin/python -> python3

要将python2.7 设为默认python 命令,请使用:

sudo ln -sf `which python2.7` `which python`
ls -l /usr/bin/python

现在应该是lrwxrwxrwx 1 root root 9 Apr 3 15:46 /usr/bin/python -> python2.7

【讨论】:

    猜你喜欢
    • 2017-11-15
    • 2022-12-02
    • 2015-11-11
    • 2012-05-22
    • 2013-04-09
    • 2018-01-10
    • 1970-01-01
    • 1970-01-01
    • 2023-02-05
    相关资源
    最近更新 更多