Running Python on Windows for Node.js dependencies

Running Python on Windows for Node.js dependencies

If you havent got python installed along with all the node-gyp dependencies, simply open Powershell or Git Bash with administrator privileges and execute:

npm install --global --production windows-build-tools

and then to install the package:

npm install --global node-gyp

once installed, you will have all the node-gyp dependencies downloaded, but you still need the environment variable. Validate Python is indeed found in the correct folder: 

*Note – it uses python 2.7 not 3.x as it is not supported*

If it doesnt moan, go ahead and create your (user) environment variable:


restart cmd, and verify the variable exists via set PYTHON which should return the variable ($env:PYTHON if using Powershell)

Lastly re-apply npm install <module>

Your problem is that you didnt set the environment variable.

The error clearly says this:

gyp ERR! stack Error: Cant find Python executable python, you can set the PYTHON env variable.

And in your comment, you say you did this:


Thats nice, but that doesnt set the PYTHON variable, it sets the PYTHONPATH variable.

Meanwhile, just using the set command only affects the current cmd session. If you reboot after that, as you say you did, you end up with a whole new cmd session that doesnt have that variable set in it.

There are a few ways to set environment variables permanently—the easiest is in the System Control Panel in XP, which is of course different in Vista, different again in 7, and different again in 8, but you can google for it.

Alternatively, just do the set right before the npm command, without rebooting in between.

You can test whether youve done things right by doing the exact same thing the config script is trying to do: Before running npm, try running %PYTHON%. If youve done it right, youll get a Python interpreter (which you can immediately quit). If you get an error, you havent done it right.

There are two problems with this:

set PYTHON=%PYTHON%;D:Python

First, youre setting PYTHON to ;D:Python. That extra semicolon is fine for a semicolon-separated list of paths, like PATH or PYTHONPATH, but not for a single value like PYTHON. And likewise, adding a new value to the existing value is what you want when you want to add another path to a list of paths, but not for a single value. So, you just want set PYTHON=D:Python.

Second, D:Python is not the path to your Python interpreter. Its something like D:PythonPython.exe, or D:PythonbinPython.exe. Find the right path, make sure it works on its own (e.g., type D:PythonbinPython.exe and make sure you get a Python interpreter), then set the variable and use it.


set PYTHON=D:PythonbinPython.exe

Or, if you want to make it permanent, do the equivalent in the Control Panel.

Running Python on Windows for Node.js dependencies

For me after installing windows-build-tools with the below comment

npm --add-python-to-path=true --debug install --global windows-build-tools

running the code below

npm config set python

has worked.

Leave a Reply

Your email address will not be published. Required fields are marked *