node-gyp: python not found - had to configure it manually in npm

On Mac OS X (Intel) v12.3.1 to make compilation of native modules work, I had to add the following to my .npmrc:

python=/usr/local/bin/python3

It took me quite a bit of time to find this trick.

This is with:

  • node.js v16.14.0
  • npm v8.5.5

Why is this needed? Why can’t node-gyp figure it out to try python3 instead? Should we document this?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 38 (20 by maintainers)

Most upvoted comments

For my case, it was better to make just symbolic link for python3 to python. it worked for me. (24-inch, M1, 2021)

Python3 was Installed using brew before.

$ cd /opt/homebrew/bin
$ sudo ln -sf python3 python

npm config set python python3 worked for me

@cclauss Calling /usr/bin/python3 on Monterey 12.3+ will ask to install Command Line Tools, and after that python3 binary will work.

For those using yarn in a (older) Rails app and a Python installation via pyenv, this finally solved it for me after hours of applying every possible suggested solution:

pyenv install 2.7.18

yarn config set python "/Users/$USER/.pyenv/shims/python2.7""

This will add that config to ~/.yarnrc

Also I made sure to undo as much of the previous given solutions in the other files like: ~/.zsh_profile ~/.zshrc ~/.npmrc

And finally I had to remove the yarn.lock file and update a webpacker version as is suggested here.

Then when running yarn it correctly installed everything.

Ah yes, I understand what’s the problem. On Mac it tries to install xcode dev tools every time and it gets stuck for 15 minutes.

Perhaps v12.3.1, not v12.13.1? Apple finally made good on its commitment to not bundle Python in the OS.

I believe that you can just type python3 on the command line and macOS will install it for you.

Most Mac developers would brew install python@3.10

For my case, it was better to make just symbolic link for python3 to python. it worked for me. (24-inch, M1, 2021)

Python3 was Installed using brew before.

$ cd /opt/homebrew/bin
$ sudo ln -sf python3 python

Alt Text

Instead of creating symlink and affecting other python projects, Create a venv in your current node project folder and do npm install again.

@jacek213 Install pyenv, python 2.7. Set python 2.7 as global.

Python 2 died 1,058 days ago on 1/1/2020. Use it at your own risk.

Perhaps v12.3.1, not v12.13.1? Apple finally made good on its commitment to not bundle Python in the OS.

Yes

I believe that you can just type python3 on the command line and macOS will install it for you.

python3 is actually there, not sure where it came from.

Most Mac developers would brew install python@3.10