6

I am trying to npm install for a project in my mac but for some reason it says python not found even though python3 command is working fine and I also set alias python to python3 in by ~/.zshrc and ~/.bash-profile and restarted several times but still the same issue.

Screenshot of the issue.

enter image description here

NOTE: See comments for the solution

7
  • 1
    try: npm config set python C:\Library\Python\Python310\python.exe via administrator Commented Apr 18, 2022 at 4:41
  • @debugger I am talking about mac Commented Apr 18, 2022 at 4:42
  • 1
    try same cmd for mac aswell. Check your python lib path and try Commented Apr 18, 2022 at 4:44
  • now getting this error stack Error: Command failed: /Library/Frameworks/Python.framework/Versions/3.10/bin/python3 -c import sys; print "%s.%s.%s" % sys.version_info[:3]; Commented Apr 18, 2022 at 4:47
  • 1
    try: python 2.7 Commented Apr 18, 2022 at 4:48

1 Answer 1

15

The problem is that Python is required in the system path to operate this command. Solutions:

  1. Install pyenv
  2. Install either Python 2.7 or Python 3.x: pyenv install 2.7.18 or pyenv install 3.9.11 (for example)
  3. If you have more than one python version, ensure one of them is set as global: pyenv global 3.9.11
  4. Add pyenv to your system path
    • On Mac, put this in your ~/.bashrc or ~/.zshrc: export PATH=$(pyenv root)/shims:$PATH, then run source ~/.bashrc or source ~/.zshrc
    • For Windows, try npm config set python C:\Library\Python\Python310\python.exe (for example) via administrator
  5. Run npm install again
Sign up to request clarification or add additional context in comments.

1 Comment

python@2 is removed from brew .. so this not work anymore

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.