How to Fix zsh: command not found: python Error?

messylean

New member
I keep getting the error zsh: command not found: python when I try to run Python scripts in my terminal. Has anyone else encountered zsh: command not found: python? I’m looking for a clear explanation and steps to fix this issue so I can run Python commands properly.
 
To fix the zsh: command not found: python error, follow these steps:
  • Try Python3: Modern macOS and Linux versions use python3. Test it by typing python3 --version in your terminal.
  • Create an Alias: Open your Zsh configuration file by running nano ~/.zshrc.
  • Add Alias Line: Scroll to the bottom and paste: alias python='python3'.
  • Save and Exit: Press Ctrl + O, Enter, then Ctrl + X.
  • Refresh Zsh: Run source ~/.zshrc to apply the changes immediately.
  • Check Path: If it still fails, ensure Python is installed and added to your $PATH environment variable.
 
To fix zsh: command not found: python, try using python3 instead, as modern macOS and Linux versions no longer include "python" by default. If that works, create an alias by adding alias python='python3' to your .zshrc file, then run source ~/.zshrc to apply the changes.
 
Here’s how to fix zsh: command not found: python error:
  • Check if Python is installed by running python3 --version.
  • If not installed, install Python via Homebrew (brew install python) on macOS or your package manager on Linux.
  • Add Python to your PATH: export PATH="/usr/local/bin:$PATH".
  • Restart the terminal.
  • Verify with python3 --version.
 
  • Open the terminal and type python3 --version to check installation.
  • If Python isn’t installed, install it via Homebrew (brew install python) or Linux package manager.
  • Add Python to PATH: echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.zshrc.
  • Run source ~/.zshrc.
  • Test with python3 --version.
 
  • Confirm Python installation with python3 --version.
  • If missing, download and install Python from python.org or use a package manager.
  • Update PATH by adding export PATH="/usr/local/bin:$PATH" in ~/.zshrc.
  • Reload the terminal with source ~/.zshrc.
  • Run python3 to ensure the command works.
 
Back
Top