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
- 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
- Installing Python on Linux
- Installing Python with Homebrew (for macOS and Linux)
Installing Python on macOS
Step 1: Download Python for macOS
- Visit the Python download website for macOS at python.org/downloads/macos.
- 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.
- Scroll down the page and select macOS 64-bit universal2 installer.
- Wait for the download to complete.
Step 2: Install Python on macOS
- Run the installer.
- Click Continue.
- Click Install.
- Enter your password and click Install Software.
- Wait for the installation to complete.
Step 3: Check Python Version
- Open the Terminal.
- Type
python3 --version
, press Enter. - 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
- Open the Terminal.
- Type
sudo apt update
, and press Enter. - Type
sudo apt install python3
, and press Enter. - Enter your password and press Enter.
Step 2: Check Python Version
- Type
python3 --version
, press Enter. - 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
- Open the Terminal.
- Type
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
then press Enter. - Wait for the installation to complete.
Step 2: Download and Install Python with Homebrew
- Type
brew install python3.10
(or whatever version), and press Enter. - Wait for the installation to complete.
Step 3: Check the Python Version with Homebrew
- Type
python3.10 --version
, press Enter. - 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.
Comments
Be the first to comment!