【问题标题】:"Can't find Python executable..." - npm install hangs“找不到 Python 可执行文件...” - npm install 挂起
【发布时间】:2015-06-04 18:24:13
【问题描述】:

我正在使用“npm install”来下载和编译我编写的一个小型 node.js 应用程序的所有依赖项。我使用的“package.json”文件是正确的,包含所有需要的信息。

其中一个要安装的包有“node-gyp”作为依赖,所以我之前已经安装了“python2”包。

现在,在某个时刻,我开始收到错误消息:

> node-gyp rebuild

gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
gyp ERR! stack     at failNoPython (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:103:14)
gyp ERR! stack     at /usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:42:11
gyp ERR! stack     at F (/usr/lib/node_modules/npm/node_modules/which/which.js:40:25)
gyp ERR! stack     at E (/usr/lib/node_modules/npm/node_modules/which/which.js:43:29)
gyp ERR! stack     at /usr/lib/node_modules/npm/node_modules/which/which.js:54:16
gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:99:15)
gyp ERR! System Linux 3.18.9-200.fc21.x86_64
gyp ERR! command "node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /srv/visitor/node_modules/phantom/node_modules/dnode/node_modules/weak
gyp ERR! node -v v0.12.1
gyp ERR! node-gyp -v v1.0.3
gyp ERR! not ok
npm WARN optional dep failed, continuing weak@0.3.4

问题似乎是缺少环境变量。

谁能指出我正确的方向?无论我在互联网上的哪个地方搜索,都没有提到“PYTHON”变量,只有“PYTHONPATH”和其他类似的。解决此问题的正确方法是什么,以免我收到这些错误?

更新 1:

根据这个线程的建议,我在执行“npm install”之前添加了这些命令:

PYTHON=/usr/sbin/python2
export PYTHON

现在我收到此错误:

> node-gyp rebuild

gyp ERR! build error
gyp ERR! stack Error: not found: make
gyp ERR! stack     at F (/usr/lib/node_modules/npm/node_modules/which/which.js:40:28)
gyp ERR! stack     at E (/usr/lib/node_modules/npm/node_modules/which/which.js:43:29)
gyp ERR! stack     at /usr/lib/node_modules/npm/node_modules/which/which.js:54:16
gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:99:15)
gyp ERR! System Linux 3.18.9-200.fc21.x86_64
gyp ERR! command "node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /srv/visitor/node_modules/phantom/node_modules/dnode/node_modules/weak
gyp ERR! node -v v0.12.1
gyp ERR! node-gyp -v v1.0.3
gyp ERR! not ok
npm WARN optional dep failed, continuing weak@0.3.4

我觉得它说“...未找到:制作...”很荒谬。有没有这样的可能?如果是,如何正确安装包?

坦率地说,我什么都不懂。有什么想法吗?

【问题讨论】:

  • 您需要设置PYTHON 环境变量。将使用该变量中的任何内容。不管PYTHONPATH 是什么。
  • @adarsh 我能说的就这么多了。你能详细说明一下吗?如果您对此做出回答,我将投票赞成。
  • 您使用的是哪个操作系统?你是如何安装python2的?尝试先在命令行中执行它
  • @irqed 操作系统是 Arch Linux。该软件包是使用“pacman -S python2”安装的。由于这是 Docker 容器创建过程的一部分,因此我没有从控制台运行 python 的实用方法。

标签: python node.js python-2.7 environment-variables


【解决方案1】:

尝试运行这个

PYTHON=$PYTHON:/usr/bin/python
export PYTHON

将此添加到配置文件(如~/.bash_profile 等,具体取决于您的shell)以使其持久化。

如果你的python没有安装在/usr/bin/python,那么你可以运行which python来找出它的安装位置。

【讨论】:

  • 将尝试尽快报告。
  • 它不起作用。它会产生以下错误:“/bin/sh: line 0: export: `:/usr/bin/python': not a valid identifier”。另外,当运行“which python”时,它说在路径中找不到“python”。
  • 哦,对不起,我在第二行写错了。使用export PYTHON。不应使用 $ 符号。我会编辑答案
  • 然后使用which python2并将该路径添加到PYTHON变量而不是/usr/bin/python
  • 或者只是创建一个适当的符号链接,如发行版文档建议 wiki.archlinux.org/index.php/python#Python_2
【解决方案2】:

首先要感谢所有帮助我解决问题的人,尤其是@adarsh。

现在真正的问题是我缺少“make”和“gcc”。起初,当编译器消息如此建议时,我觉得这很荒谬。但请记住,这是从 Docker 注册表中提取的图像。

我在 Dockerfile 中添加了“pacman -S --needed --noconfirm make gcc”,构建过程成功完成。

不用说,我还需要对环境变量进行建议的更改。

【讨论】:

  • 我们需要在哪里添加一行:pacman -S --needed --noconfirm make gcc
【解决方案3】:

这对我有用..

node-gyp --python C:\Users\username\.windows-build-tools\python27\python.exe build

我们需要指向 python.exe 而不仅仅是安装文件夹。

【讨论】:

    【解决方案4】:

    CMD

    如果是本地驱动器: npm install express-generator

    #npm install express-generator -g
    #express --ejs .
    

    选择是

    #y
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-30
      • 2014-06-27
      相关资源
      最近更新 更多