Blog / Python / zsh

How to Fix 'zsh: command not found: python' Error After Installing Python via Brew on a Mac

If you've installed Python using Brew on a Mac, you may encounter the zsh: command not found: python error when trying to run Python from the terminal.

The reason for this is that when using brew, the location of the Python package is not automatically passed to the zsh profile. As a result, you may encounter issues with Python packages not being found or failing to import properly.

To fix this issue, you can try

echo "alias python=/opt/homebrew/bin/python3" >> ~/.zshrc

This command will add the correct alias to the file locations. After run the command, try running the python command again in your terminal to verify that Python is now working correctly.

python --version

Sometimes ya gotta restart the terminal. Just close that window, then open it back up. Now you can check if Python's working.

If you've run into this error for a different reason or if you've come up with another solution, I'd love to hear about it! Feel free to share your experience and insights in the comments below. It could be super helpful for others who might be dealing with similar issues. So don't hold back, let's collaborate and make troubleshooting easier for everyone!