简体   繁体   English

“找不到 Python 可执行文件……” - npm install 挂起

[英]“Can't find Python executable…” - npm install hangs

I am using "npm install" to download and compile all the dependencies of a small node.js app I have written.我正在使用“npm install”来下载和编译我编写的一个小型 node.js 应用程序的所有依赖项。 The "package.json" file I am using is correct and contains all the needed information.我使用的“package.json”文件是正确的,包含所有需要的信息。

One of the packages to be installed has "node-gyp" as a dependency, so I have previously installed the "python2" package.要安装的包之一具有“node-gyp”作为依赖项,因此我之前安装了“python2”包。

Now, at a certain point I start getting error messages:现在,在某个时刻,我开始收到错误消息:

> 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

The issues seems to be that an environment variable is missing.问题似乎是缺少环境变量。

Can anyone point me in the right direction?任何人都可以指出我正确的方向吗? No matter where I search on the Internet, there is no mention of a "PYTHON" variable, only "PYTHONPATH" and others like it.无论我在互联网上的何处搜索,都没有提到“PYTHON”变量,只有“PYTHONPATH”和其他类似的变量。 What is the correct way to fix this, so that I do not get those errors?解决此问题的正确方法是什么,以免我收到这些错误?

UPDATE 1:更新1:

After following advice from this thread I added these commands before executing "npm install":在遵循此线程的建议之后,我在执行“npm install”之前添加了这些命令:

PYTHON=/usr/sbin/python2
export PYTHON

Now I am getting this error:现在我收到此错误:

> 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

I find it absurd that it says "...not found: make...".我觉得它说“......没有找到:制作......”很荒谬。 Is there any possibility of it being so?有没有可能是这样? If yes, how come packages install correctly?如果是,软件包如何正确安装?

Frankly, I do not understand a thing.坦白说,我什么都不懂。 Any ideas?有任何想法吗?

Try running this尝试运行这个

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

Add this to profile file (like ~/.bash_profile etc. depending on your shell) to make it persistent.将此添加到配置文件(如~/.bash_profile等,取决于您的外壳)以使其持久化。

If your python isn't installed in /usr/bin/python then you can run which python to find out where it is installed.如果你的 python 没有安装在/usr/bin/python那么你可以运行which python来找出它的安装位置。

First things first: I want to thank all who pitched in to help me with my issue, and especially @adarsh.第一件事:我要感谢所有帮助我解决我的问题的人,尤其是@adarsh。

Now the real issue was that I was missing "make" and "gcc".现在真正的问题是我缺少“make”和“gcc”。 At first, when a compiler message suggested so, I found it absurd.起初,当一条编译器消息建议这样做时,我觉得这很荒谬。 But keep in mind that this is an image PULLed from the Docker registry.但请记住,这是从 Docker 注册表中提取的图像。

I added "pacman -S --needed --noconfirm make gcc" in my Dockerfile, and the build process completes successfully.我在 Dockerfile 中添加了“pacman -S --needed --noconfirm make gcc”,构建过程成功完成。

It should go without saying, that I also needed to make the suggested changes to the environmental variables.不用说,我还需要对环境变量进行建议的更改。

This worked for me..这对我有用..

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

We need to point to python.exe not just up to the installation folder.我们需要指向python.exe而不仅仅是指向安装文件夹。

In CMDCMD 中

if local on drive: npm install express-generator如果本地在驱动器上: npm install express-generator

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

choose yes选择是

#y

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 MacOS Big Sur 中出现 NPM 错误“找不到 Python 可执行文件” - NPM Error "Can't find Python executable" in MacOS Big Sur 呃! 堆栈错误:在使用Windows 10的克隆存储库上尝试运行npm install时找不到Python可执行文件 - ERR! stack Error: Can't find Python executable while trying to run npm install, on a cloned repo using windows 10 npm - “找不到 Python 可执行文件“python”,您可以设置 PYTHON env 变量。” - npm - "Can't find Python executable "python", you can set the PYTHON env variable." 找不到Python可执行文件 - Can't find Python executable 错误:找不到Python可执行文件“ python” - Error: Can't find Python executable “python” 找不到 Python 可执行文件“python” - Can't find Python executable "python" NPM安装无法在MAC中执行Python - NPM install can't execute Python in MAC Docker 找不到 Python venv 可执行文件 - Docker can't find Python venv executable WLS2 UBUNTU:npm 错误! 吉普错误! 堆栈错误:找不到 Python 可执行文件“python”,您可以设置 PYTHON 环境变量。 和更多 - WLS2 UBUNTU: npm ERR! gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable. and more 码头运行 <image> 错误:找不到要运行的python可执行文件 - docker run <image> Error: Can't find python executable to run
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM