11

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.

One of the packages to be installed has "node-gyp" as a dependency, so I have previously installed the "python2" package.

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. What is the correct way to fix this, so that I do not get those errors?

UPDATE 1:

After following advice from this thread I added these commands before executing "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?

dlyk1988
  • 415
  • 1
  • 7
  • 22
  • You need to set the `PYTHON` environment variable. What ever is in that variable will be used. Doesn't matter what `PYTHONPATH` is. – adarsh Mar 31 '15 at 12:07
  • @adarsh That much I can tell. Could you please elaborate? If you make an answer out of it, I shall upvote. – dlyk1988 Mar 31 '15 at 12:09
  • which OS are you using? how did you install python2? try executing it in command line first – irqed Mar 31 '15 at 12:14
  • @irqed The OS is Arch Linux. The package was installed with "pacman -S python2". Since this is a part of the creation process for a Docker container, I have no practical way of running python from the console. – dlyk1988 Mar 31 '15 at 12:17
  • possible duplicate of [Running Python on Windows for Node.js dependencies](http://stackoverflow.com/questions/15126050/running-python-on-windows-for-node-js-dependencies) – LisaMM Aug 06 '15 at 09:58

4 Answers4

6

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.

If your python isn't installed in /usr/bin/python then you can run which python to find out where it is installed.

adarsh
  • 6,738
  • 4
  • 30
  • 52
  • Will try and report back ASAP. – dlyk1988 Mar 31 '15 at 12:26
  • It does not work. It produces this error: "/bin/sh: line 0: export: `:/usr/bin/python': not a valid identifier". Also, when running "which python", it says that no "python" can be found inside the path. – dlyk1988 Mar 31 '15 at 12:40
  • 1
    Oh sorry, I made a mistake in the second line. Use `export PYTHON`. The $ sign shouldn't be used. I'll edit the answer – adarsh Mar 31 '15 at 12:44
  • 1
    Then use `which python2` and add that path to the `PYTHON` variable instead of `/usr/bin/python` – adarsh Mar 31 '15 at 12:54
  • 1
    or just create a proper symlink like distro docs suggest https://wiki.archlinux.org/index.php/python#Python_2 – irqed Mar 31 '15 at 13:01
  • @adarsh Still getting error. I used "PYTHON=$PYTHON:/usr/sbin/python2" and "export PYTHON". Now it says: "gyp ERR! stack Error: Can't find Python executable ":/usr/sbin/python2", you can set the PYTHON env variable.". – dlyk1988 Mar 31 '15 at 13:05
3

First things first: I want to thank all who pitched in to help me with my issue, and especially @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.

I added "pacman -S --needed --noconfirm make gcc" in my Dockerfile, and the build process completes successfully.

It should go without saying, that I also needed to make the suggested changes to the environmental variables.

dlyk1988
  • 415
  • 1
  • 7
  • 22
1

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.

hacker
  • 342
  • 1
  • 4
  • 14
-3

In CMD

if local on drive: npm install express-generator

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

choose yes

#y
Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73