Python command not found - Mac

Page content

How to Install Python Command on Mac

Python is a popular programming language used for a variety of applications. If you are encountering the “Python command not found” error on your Mac, here is a step-by-step guide to help you install Python.

Why Python Command Not Found?

The “Python command not found” error typically occurs when Python is not installed on your Mac or when the system cannot locate the Python executable in the PATH environment variable.

Installation Steps

To install Python on your Mac and resolve the “Python command not found” error, follow these steps:

  1. Check if Python is Installed: Open the Terminal and type python --version to check if Python is already installed on your system.

  2. Install Homebrew: If Python is not installed, you can use Homebrew, a package manager for macOS, to install Python. If you don’t have Homebrew installed, you can do so by running the following command in the Terminal:

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
  3. Install Python: Once Homebrew is installed, you can install Python by running the following command:

    brew install python
    
  4. Verify Installation: After the installation is complete, verify that Python is installed by running python --version in the Terminal.

  5. Update PATH Variable: If you still encounter the “Python command not found” error, you may need to update your PATH variable to include the directory where Python is installed. You can do this by adding the following line to your .bash_profile or .zshrc file:

    export PATH="/usr/local/opt/python/libexec/bin:$PATH"
    
  6. Restart Terminal: After updating the PATH variable, restart your Terminal or run source ~/.bash_profile (or source ~/.zshrc) to apply the changes.

Conclusion

By following these steps, you should be able to successfully install Python on your Mac and resolve the “Python command not found” error. Python is a versatile language that can be used for various programming tasks, so having it installed on your system is essential for development and scripting purposes.