【问题标题】:react-native raises weird python error when initing appreact-native 在启动应用程序时引发奇怪的 python 错误
【发布时间】:2020-12-16 21:56:03
【问题描述】:

我刚刚输入了npx react-native init cinetogo,我收到了这个错误:

stw041269:mobile hugovillalobos$ npx react-native init cinetogo
gyp ERR! configure error 
gyp ERR! stack Error: Command failed: /Users/hugovillalobos/anaconda3/bin/python -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack   File "<string>", line 1
gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack                                ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack 
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:294:12)
gyp ERR! stack     at ChildProcess.emit (events.js:198:13)
gyp ERR! stack     at maybeClose (internal/child_process.js:982:16)
gyp ERR! stack     at Socket.stream.socket.on (internal/child_process.js:389:11)
gyp ERR! stack     at Socket.emit (events.js:198:13)
gyp ERR! stack     at Pipe._handle.close (net.js:606:12)
gyp ERR! System Darwin 17.7.0
gyp ERR! command "/Users/hugovillalobos/.nvm/versions/node/v10.16.0/bin/node" "/Users/hugovillalobos/.nvm/versions/node/v10.16.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/hugovillalobos/.npm/_npx/19812/lib/node_modules/react-native/node_modules/fsevents
gyp ERR! node -v v10.16.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 

我没有找到任何有相同错误的人的参考,

【问题讨论】:

    标签: react-native


    【解决方案1】:

    据此answer

    Node.js 是用 GYP 构建的

    根据这个answer

    node 在后台使用了一些 python 脚本,尽管 Node 主要是用 C++ 编写的

    您的问题是您安装了安装了 python 3.x 的 Anaconda 版本 3。但是对于 Node 需要 python 2.x 才能与 GYP 一起使用。 正如你在日志中看到的,有一些语法错误:

    gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
    gyp ERR! stack                                ^ 
    gyp ERR! stack SyntaxError: invalid syntax
    

    print 语句使用 Python 2.x 的语法,但你的 anaconda 使用的是 python 3.x。所以它会抛出语法错误。

    解决方案:安装 python 2.x(2.6 或 2.7),通过安装 anaconda 2 或独立的 python 2.x 版本,然后尝试执行 npx。

    【讨论】:

    • 我实际上在我的 mac 中安装了 python 2.7,但由于某种原因,默认版本现在是 3.7。如果我输入python,我得到的不是 2.7,而是 3.7
    • @HuLuViCa ,这是因为,当您安装 anaconda 时,应该有一个步骤询问您是否将 conda/python 作为默认添加,系统范围。因此,在接受并安装 Anaconda 之后,您将失去对 Anaconda 中也包含的其他独立软件包的控制。现在,每当您想要访问 Anaconda 中已包含的内容时,您都会获得该版本。不是独立的。
    • @HuLuViCa 解决方案:您需要通过 .bashrc(或其他配置文件)在 PATH 变量中添加独立版本的 python 遵循此answer
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-28
    相关资源
    最近更新 更多