DEV Community

loading...
PostCo

Solve node-gyp build error due to PYTHONPATH

Andy Chong
I'm a software engineer working in PostCo. And we're hiring @ postco.co/careers!
Updated on ・1 min read

Update

From node-gyp@5.1.0 onwards, python3 will be used for the build, therefore please follow the steps below, but replace the last step with

PYTHONPATH=python3 && npm i

Recently, I faced the problem where node-gyp rebuild failed due to PYTHONPATH is pointing to python3. This is due to python2 is being deprecated, and python now points to python3 by default. While node-gyp requires python2 to build.

To solve this on macOS, just make sure you reinstall python 2 and python 3 and point PYTHONPATH environment variable to python2.

# Only do this if `where python2` output nothing
brew uninstall --ignore-dependencies python2 python3
brew install python2 python3 


PYTHONPATH=python2 && npm i

DONE!


References

Discussion (0)