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

Minh Vu

By Minh Vu

Updated Nov 04, 2023

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

Disclaimer: All content on this website is derived directly from my own expertise and experiences. No AI-generated text or automated content creation tools are used.

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.

Contents

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 the Latest Python 3 Release - Python x.xx.x option for the latest version. My suggestion is to choose Python 3.10.x as it's a stable version.
  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 shows 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, and press Enter.
  3. Type sudo apt install python3, and 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), and press Enter.
  2. Wait for the installation to complete.

Step 3: Check the 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 installing Python.

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

Minh Vu

Minh Vu

Software Engineer

Hi guys 👋, I'm a developer specializing in Elastic Stack and Next.js. My blog shares practical tutorials and insights based on 3+ years of hands-on experience. Open to freelance opportunities — let's get in touch!

Comments

Be the first to comment!

Leave a Comment

Receive Latest Updates 📬

Get every new post, special offers, and more via email. No fee required.