Python command not found on Mac OS

Python command not found on Mac OS

If you get the "python command not found" error on macOS, it means that Python is not installed on your computer or is not in your PATH environment variable. To fix this error, you can try one of the following solutions:

  1. Install Python using the official installer from the Python website (https://www.python.org/downloads/). This will automatically add Python to your PATH, so you should be able to use the python command in a terminal window after installation.

  2. If you already have Python installed, you can manually add it to your PATH. To do this, open a terminal window and run the following commands:

export PATH=$PATH:/usr/local/bin/python3
  1. Replace /usr/local/bin/python3 with the path to your Python installation, if it is different.

  2. Alternatively, you can use the full path to the Python executable when running a Python script, instead of using the python command. For example, if Python is installed at /usr/local/bin/python3, you can run a Python script like this:

/usr/local/bin/python3 my_script.py

How to install Python

To install Python on Windows, macOS, and Linux, you can follow these general steps:

  1. Download the latest version of Python from the official Python website (https://www.python.org/downloads/). Make sure to download the version for your operating system.

  2. Once the download is complete, run the installer and follow the on-screen instructions to complete the installation.

  3. After the installation is finished, open a new terminal window and type python to run the Python interpreter. You should see the Python version and the prompt >>>, which indicates that Python is ready to accept commands.

  4. To verify that Python was installed correctly, you can try running a simple program, such as the "Hello, World!" program. In the Python interpreter, type the following:

print("Hello, World!")

This should print the message "Hello, World!" on the screen, indicating that Python is working properly.

To exit the Python interpreter, type exit() or press CTRL + D.

Related articles

Ruslan Osipov
Written by author: Ruslan Osipov