We Are Going To Discuss About NPM Error “Can’t find Python executable” in MacOS Big Sur. So lets Start this Python Article.
NPM Error “Can’t find Python executable” in MacOS Big Sur
- How to solve 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
- 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
Solution 1
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
Original Author PaulMest Of This Content
Solution 2
Reading the gyp-node
source might helps. Here are some steps you can try.
-
Install python2. You should make sure that in the terminal,
which -a python2
only returns onepython2
andpython2 -V
returns the correct 2.x version. -
override
PYTHON
env.export PYTHON=python2
. -
Rerun the install.
If there’s still an error, probably the error message is different.
Original Author willnode Of This Content
Solution 3
I believe you can explicitly define env var by prefixing it with npm_config
:
$ export npm_config_python=/path/to/python
check if that is configured by listing the config:
$ npm config list
...
; environment configs
python = "/path/to/python"
this should be picked up by node-gyp
.
Another approach would be to define it in .npmrc
python = "/path/to/python"
A third approach would be to set it globaly:
npm config --global set python /path/to/python
Original Author Pedreiro Of This Content
Solution 4
From the terminal messages, you are installing an old version of node-gyp ([email protected]). From a quick search, it seams that this version requires python 2. Python 2 should be present in Big Sur. Properly setting the path, should work:
export PATH=/usr/bin/python:$PATH
Also, try:
export PYTHON=/usr/bin/python
Original Author kgiannakakis Of This Content
Conclusion
So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.