avatarWouter

Summary

The website content describes a solution to an error encountered while running yarn for an old project, where the build process failed due to an incorrect Python path reference, specifically looking for "python2" in the PATH.

Abstract

The article details a troubleshooting process for a common Node.js build error related to Python. The author encountered this issue while working on an outdated project, which required a specific version of a Sass library. The error messages indicated that the build script was unable to locate the correct Python executable, despite Python being properly installed and accessible from the command line. The author deduced that the script was searching for Python in the wrong directory. The solution involved updating Python to the latest version, confirming its installation by running it from the command line, setting the correct Python installation path in the system's environment variables, and finally, using npm config set python to explicitly tell npm where to find the Python executable. The article concludes with a suggestion to use an AI service called ZAI.chat, which is presented as a cost-effective alternative to ChatGPT Plus (GPT-4).

Opinions

  • The author believes that updating Python and ensuring its correct path is set can resolve the gyp verb check python error.
  • The author suggests that even when Python is installed, it might be necessary to explicitly set its location for npm to avoid build errors.
  • The author recommends using the npm config set python command to configure the Python path for npm and yarn scripts.
  • The author endorses ZAI.chat as a more affordable AI service compared to ChatGPT Plus (GPT-4), implying that it offers similar performance and functionality.

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: python2

The 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.exe

And that’s it! Now the yarn script should work again.

Python
Yarn
NPM
Recommended from ReadMedium