Quickfix: NPM err: gyp verb check python checking for Python executable “python2” in the PATH
Last week I was working on a very old project that was using a very old sass library. When trying to build the project using the yarn command, I got the following error:
gyp verb check python checking for Python executable "python2" in the PATH
npm ERR! gyp verb `which` failed Error: not found: python2The console showed me a lot of error lines:

Something was wrong while trying to execute the Python script when building. The error didn’t make sense to me because the Pyton executable worked fine. Opening a new command line and entering python even showed me this:

Meaning python was correctly installed. One of the error messages showed me this:
npm ERR! gyp ERR! stack Error: Can't find Python executable "C:\Python310\python.EXE", you can set the PYTHON env variable.Which made me come to the conclusion: the script was looking for Python at the wrong place. But why? I had set the python in my system environments path. So after digging a bit I found the solution
How to solve this
Install python
Even if you have python installed it might be a good idea to update your installation to the latest version. Simply head to this download page and download and install python.

You might have to restart your computer after doing this step. To check if it working simply enter “python” in a new command prompt.
Set the correct location of your python installation
Depending on the version of Python you have installed, the folder location is different. Open your file explorer on the c drive and look for a python folder.

In my case Python was installed under C:\Python310.
Tell npm where our Python is located
You can use the NPM config command to configure the python location on your computer. Simply run npm config set python followed by the install location. In my case I had to run:
npm config set python C:\Python310\python.exeAnd that’s it! Now the yarn script should work again.





