“找不到 Python 可执行文件...” - npm install 挂起
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29368205/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Can't find Python executable..." - npm install hangs
提问by dlyk1988
I am using "npm install" to download and compile all the dependencies of a small node.js app I have written. The "package.json" file I am using is correct and contains all the needed information.
我正在使用“npm install”来下载和编译我编写的一个小型 node.js 应用程序的所有依赖项。我使用的“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 [email protected]
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. What is the correct way to fix this, so that I do not get those errors?
任何人都可以指出我正确的方向吗?无论我在互联网上的何处搜索,都没有提到“PYTHON”变量,只有“PYTHONPATH”和其他类似的变量。解决此问题的正确方法是什么,以免我收到这些错误?
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 [email protected]
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?
坦白说,我什么都不懂。有任何想法吗?
采纳答案by dlyk1988
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". 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.
现在真正的问题是我缺少“make”和“gcc”。起初,当一条编译器消息建议这样做时,我觉得这很荒谬。但请记住,这是从 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.
不用说,我还需要对环境变量进行建议的更改。
回答by adarsh
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
以找出它的安装位置。
回答by MEAN_guy
In CMD
在CMD 中
if local on drive:npm install express-generator
如果本地在驱动器上:npm install express-generator
#npm install express-generator -g
#express --ejs .
choose yes
选择是
#y
回答by hacker
This worked for me..
这对我有用..
node-gyp --python C:\Users\username\.windows-build-tools\python27\python.exe build
We need to point to python.exenot just up to the installation folder.
我们需要指向python.exe而不仅仅是指向安装文件夹。