【问题标题】:Why does NVM use the incorrect version of Python?为什么 NVM 使用不正确的 Python 版本?
【发布时间】:2020-05-19 03:52:04
【问题描述】:

我在使用 node-gyp 包时遇到了一些问题,我相信这是因为我需要使用 python 2.7 而不是 python 3。

我已经设置了我的 PATH 环境变量,所以当我执行 python --version 时,输出是 Python 2.7.16

但是,在同一个终端中,当我转到 yarn 时,安装我的项目。它失败了,我可以看到日志的输出是:

Command: node-gyp rebuild
Arguments:
Directory: /Users/myname/Documents/myproject
Output:
gyp info it worked if it ends with ok
gyp info using node-gyp@5.0.5
gyp info using node@12.14.0 | darwin | x64
gyp info find Python using Python version 3.7.3 found at "/Users/myname/anaconda3/bin/python"

我也在使用 nvm。卡塔利娜 10.15.2。节点 12.14.0。 NVM 0.33.11。

为什么我的终端版本显示我使用 2.7,但日志显示命令 node-gyp rebuild 使用 3.7.3?如果我已经设置了我的环境变量,我可以改变什么来纠正这个问题?和nvm有关吗?

【问题讨论】:

    标签: python node.js macos nvm


    【解决方案1】:

    nvm 遇到了同样的问题。 为我解决的问题是使用nvm uninstall v 卸载我当前的节点版本,然后使用nvm install v 再次安装它。在此之后,python 版本被完美地检测到。认为这是由于安装新节点版本时的配置缓存或类似情况造成的。

    【讨论】:

      【解决方案2】:

      解决了!你可以这样做:

      npm install --python=python2.7

      或将其设置为始终使用:

      npm config set python python2.7

      从这里捏住 => How to use a different version of python during NPM install?

      【讨论】:

      • 它是为纱线.. 如果你认为它是重复的,请将其标记为重复。不要只是复制答案..
      猜你喜欢
      • 2021-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多