NPM Error “Can’t find Python executable” in MacOS Big Sur

This one also plagued me for a week because node-gyp could actually find my Python instance just fine, but then a later build step was not properly configured and all of the popular answers weren’t able to pick up Python. My steps to resolve on macOS Monterey (12.3.1)…

$ brew install pyenv

# Any modern version python should do. I don't think Python 2 is required any more.
$ pyenv install 3.10.3
$ pyenv global 3.10.3

# Add pyenv to your PATH so that you can reference python (not python3)
$ echo "export PATH=\"\${HOME}/.pyenv/shims:\${PATH}\"" >> ~/.zshrc

# open a new terminal window and confirm your pyenv version is mapped to python
$ which python
$ python --version

# Now try to re-run yarn install
$ yarn

Leave a Comment