【问题标题】:NPM install can't execute Python in MACNPM安装无法在MAC中执行Python
【发布时间】:2018-11-27 18:05:03
【问题描述】:

我是 MAC 新手(OSX 版本是 High Sierra 10.13.3)。我使用来自 python.org 的安装程序安装了 python 3.6.5,我也尝试通过运行 brew install python 来使用 brew 进行安装。现在,我尝试在 Angular 项目中运行 sudo npm install,但出现以下错误:

gyp verb check python checking for Python executable "/path/to/python3/python" in the PATH
gyp verb `which` failed Error: not found: /path/to/python3/python
gyp ERR! stack Error: Can't find Python executable "/path/to/python3/python", you can set the PYTHON env variable.

我已经尝试了这里的所有答案:

python location on mac osx

Can't find Python executable "python"

在我的项目文件夹中,我执行以下操作:

当我输入 'which python' 我得到:

/usr/local/opt/python/libexec/bin/python

当我输入“which python3.6.5”时,我得到:

/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6

【问题讨论】:

  • 首先,您已经在 Apple 预装的一个 Python 之上安装了至少两个额外的 Python,而不仅仅是一个。那只会让事情变得更加混乱。卸载其中一个。
  • 第二,你有没有把文字字符串/path/to/python3/path/to/python3/python 放在某个地方?如果是这样,您应该将其替换为 python3 的实际路径,例如 /Library/Frameworks/Python.framework/Versions/3.6/bin//Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
  • @abarnert 正确。我安装了最新版本,因为我知道 MAC 带有默认版本,但是当我运行 npm install 时,它说我需要 python。话虽如此,我在mac的启动器中看到了一个可执行文件,但是当我将它拖到垃圾桶时,它不会被卸载。有什么安全的方法吗?
  • 首先,你不能卸载macOS自带的Python,你也不想卸载。但是,您可以卸载两个 Python 3.6 版本中的任何一个。最简单的方法是brew unlink python,它应该删除 Homebrew 一个,留下 python.org 一个。
  • 同时,如果你使用gyp,AFAIK 那是一个不支持 Python 3 并且永远不会支持的死项目,这意味着安装 Python 3.6 将无济于事。要么使用 Apple 的 Python 2.7,要么安装另一个 Python 2.7。 IIRC,对于前者,它应该像npm install --python=python2.7 一样简单。但是,如果您搜索这方面的帮助,而不是实际不需要的 Python 安装帮助,您可能会找到更好的信息。

标签: python macos npm


【解决方案1】:

对我来说,这一切都是因为 nodejs 版本而发生的。

Node 16+版本不支持“node-sass”:“^4.14.1”,所以我必须安装nvm并降级macbook中的nodejs如下

  • 在安装 nvm 之前,在终端中运行:touch ~/.bash_profile

  • 之后,在终端中运行:curl -o-
    https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | 重击

  • 重要... - 不要忘记重新启动终端或使用命令 source ~/.nvm/nvm.sh(这将刷新
    中的可用命令 您的系统路径)。

  • 在终端中,使用命令 nvm --version 你应该会看到
    版本

  • bash nvm install 14.17.0

【讨论】:

    【解决方案2】:

    看来我的 node_modules 文件夹搞砸了。我删除了 repo 并再次克隆,它工作了。

    【讨论】:

      猜你喜欢
      • 2023-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多