Home//

How to Fix python: command not found on macOS and Linux

How to Fix python: command not found on macOS and Linux

Minh Vu

By Minh Vu

Updated Nov 04, 2023

There are several common cases where the python: command not found error occurs:

  • You have not installed Python yet.
  • You have installed Python, but you have not added it to the system's PATH.

To fix those issues, you will need to:

  • Install Python.
  • Add Python to the system's PATH.

I will show you how to fix all those issues in the next section, keep reading and find what fits your case.

Table of Contents

Follow the guidelines below to fix the python: command not found error. You can skip one or more sections if you have already done it.

  1. Installing Python and Adding Python to the System's PATH
  2. Conclusion

Installing Python and Adding Python to the System's PATH

Depending on your OS, you can choose one of the following ways to install Python.

Installing Python on macOS

Step 1: Download Python for macOS

  1. Visit the Python download website for macOS at python.org/downloads/macos.
  2. You can choose Latest Python 3 Release - Python x.xx.x for the latest version. My suggestion is to choose Python 3.10.x.
  3. Scroll down the page and select macOS 64-bit universal2 installer.
  4. Wait for the download to complete.

Step 2: Install Python on macOS

  1. Run the installer.
  2. Click Continue.
  3. Click Install.
  4. Enter your password and click Install Software.
  5. Wait for the installation to complete.

Step 3: Check Python Version

  1. Open the Terminal.
  2. Type python3 --version, press Enter.
  3. Similarly, if it shows something like Python 3.12.0, then your installation is fine.

Installing Python on Linux

For Linux, Python is usually pre-installed. The default version is 3.7.x, if you want to install another version, you can install with Homebrew instead.

The below section only show you how to install the default Python version on Linux.

Step 1: Download and Install Python on Linux

  1. Open the Terminal.
  2. Type sudo apt update, press Enter.
  3. Type sudo apt install python3, press Enter.
  4. Enter your password and press Enter.

Step 2: Check Python Version

  1. Type python3 --version, press Enter.
  2. If it shows something like Python 3.7.3, then your installation is fine.

Installing Python with Homebrew (for macOS and Linux)

Step 1: Download and Install Homebrew

  1. Open the Terminal.
  2. Type /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" then press Enter.
  3. Wait for the installation to complete.

Step 2: Download and Install Python with Homebrew

  1. Type brew install python3.10 (or whatever version), press Enter.
  2. Wait for the installation to complete.

Step 3: Check Python Version with Homebrew

  1. Type python3.10 --version, press Enter.
  2. If it shows something like Python 3.10.x, then your installation is fine.

Conclusion

That's all for this tutorial, we have fixed the python: command not found error by install Python.

If you have any problems, feel free to leave a comment below.

You can search for other posts at home page.
Minh Vu

Minh Vu

Software Engineer

Hi guys, I'm the author of WiseCode Blog. I mainly work with the Elastic Stack and build AI & Python projects. I also love writing technical articles, hope you guys have good experience reading my blog!