Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
编译node.js“出现”;名称错误:全局名称';文件';“未定义”;_Node.js - Fatal编程技术网

编译node.js“出现”;名称错误:全局名称';文件';“未定义”;

编译node.js“出现”;名称错误:全局名称';文件';“未定义”;,node.js,Node.js,我有python2和python3,我运行./configure,它可以工作。但我运行make make -C out BUILDTYPE=Release V=1 make[1]: Entering directory `/home/colin4124/MyProgram/node/out' LD_LIBRARY_PATH=/home/colin4124/MyProgram/node/out/Release/lib.host:/home/colin4124/MyProgra>m/node/

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

make -C out BUILDTYPE=Release V=1 make[1]: Entering directory `/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; export 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 Traceback (most recent call last): File "../../tools/gen-postmortem-metadata.py", line 479, in emit_config(); File "../../tools/gen-postmortem-metadata.py", line 432, in emit_config out = file(sys.argv[1], 'w'); NameError: global name 'file' is not defined make[1]: *** [/home/colin4124/MyProgram/node/out/Release/obj/gen/debug-support.cc] Error 1 make[1]: Leaving directory `/home/colin4124/MyProgram/node/out' make: *** [node] Error 2 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_库_路径;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行,中 emit_config(); 文件“./../tools/gen postmortem metadata.py”,第432行,在emit_config中 out=文件(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:**[node]错误2
我怎么能解决它,想想你

看起来您的默认Python是3.x,但是节点构建脚本需要Python 2.x

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

export PYTHON=`which python2`

这是因为默认的
python
python3.x
。Node.js建议编译源代码。
尝试通过以下方式检查
python
命令:

ls -l /usr/bin/python
它将显示
lrwxrwx1根根目录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

现在应该是
lrwxrwx1根目录9 Apr 3 15:46/usr/bin/python->python2.7

确保运行
Make distclean
以开始新的构建。另外,它假设您的Python 2.x可执行文件名为
python2
,这在您的设置中可能会有所不同。我不这么认为。因为我将python2设置为Python,这意味着当我运行Python时,它将运行python2
file()
未定义表示脚本正在使用Python 3运行。我已经通过您的anwer设置了它,但脚本仍在使用Python3运行,下一步该怎么做?Python-V说了什么?如果它说是Python2.x,也许可以尝试完全删除节点源目录,并解压源归档以重新开始。我已经解决了它。因为run“Python”是run“python3”,所以我将run“Python”设置为run“python3”。