If you are seeing the error zsh: command not found: python3
In your terminal, it simply means Python 3 is not installed on your system, or it is installed, but not correctly linked to your shell. To fix it, you need to either install Python 3 or ensure it’s accessible via your shell’s PATH.
Why Am I Seeing This Error?
In plain terms, when you see the “zsh: command not found” error after typing python3
in your terminal, it means Zsh (your shell) doesn’t know where to find the python3
executable. This happens because your system tries to locate the Python 3 binary, but it either doesn’t exist or isn’t accessible through your current PATH.
This “zsh: command not found” issue is common on freshly installed macOS or Linux systems, especially those that come without Python 3 pre-installed. If Python is installed but under a different name, or if the directory isn’t included in your $PATH
You will keep running into the zsh: command not found error whenever you try to use Python-related commands.
This usually happens because:
- Python 3 is not installed.
- Python is installed, but not under the name
python3
. - Your system’s PATH does not include the directory where Python is located.
- You’re using a clean macOS/Linux install that only comes with Python 2 (or none at all).
Step-by-Step Solution
1. Check If Python 3 is Already Installed:
Open your terminal and run:
which python3
If it returns nothing, Python 3 is not installed, or it’s not in your system’s PATH.
2. Install Python 3:
- On macOS (using Homebrew)
If you do not have Homebrew, install it:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then install Python 3:
brew install python
Once installed, confirm:
python3 --version
You should see something like Python 3.12.x
.
- On Ubuntu/Linux
Update package lists and install Python 3:
sudo apt update
sudo apt install python3
Then confirm:
python3 --version
For official installation instructions, see the Python Docs.
3. Ensure It’s in Your PATH:
If Python is installed but the terminal still does not recognize it, the PATH
The variable might not include the location where Python 3 is installed.
You can add it manually to your Zsh config:
1. Find where Python is installed:
which python3
Example output:
/opt/homebrew/bin/python3
2. Open your .zshrc
file:
nano ~/.zshrc
3. Add this line at the end:
export PATH="/opt/homebrew/bin:$PATH"
4. Save and close (CTRL + X
, then Y
, then Enter
).
5. Reload config:
source ~/.zshrc
6. Now test:
python3 --version
4. Create an Alias (Optional but Handy):
If your system recognizes Python 3 only with the python3
command, but you’d prefer to use just python
to save time, you can create a shortcut (alias) for convenience.
echo 'alias python=python3' >> ~/.zshrc
source ~/.zshrc
Now typing python
will automatically invoke Python 3.
Final Tips, Warnings & Notes
Even after you fix the zsh: command not found: python3
error, there are a few important things to keep in mind to avoid future issues, especially if you are going to use Python frequently for development, scripting, or education.
1. Python Versions and Compatibility:
- Python 2 vs Python 3: macOS (especially older versions) used to come preinstalled with Python 2, which is now deprecated and no longer maintained. Python 3 brought in major updates that are not backward compatible with Python 2, making it the current and widely accepted version for modern development.
- If you type
python
And it runs Python 2; it might confuse you if you expect Python 3 behavior. - Always use
python3
andpip3
unless you manually configure aliases (we’ll explain this below).
2. Use Aliases Wisely:
If you want to simplify your workflow, you can create aliases in your shell config file (~/.zshrc
for Zsh or ~/.bashrc
for Bash):
alias python=python3
alias pip=pip3
Then reload your shell:
source ~/.zshrc
Now, every time you type python
It will run Python 3 instead of Python 2. This is a safe and user-friendly way to avoid confusion.
3. Install pip (if not already installed):
After installing Python 3, pip3
(the Python package manager) It should come bundled. But if not, you can install it manually:
On macOS/Linux:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
Then confirm:
pip3 --version
More info: https://pip.pypa.io
4. Use pyenv
for Managing Multiple Python Versions:
If you are a developer or student working on multiple Python projects, each needing a different Python version, pyenv Is your best friend.
Install pyenv:
On macOS with Homebrew:
brew install pyenv
On Linux:
curl https://pyenv.run | bash
Add the following to your ~/.zshrc
:
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv virtualenv-init -)"
Then restart your terminal or run:
source ~/.zshrc
Install Python using pyenv:
pyenv install 3.12.3
pyenv global 3.12.3
This makes managing and switching between Python versions super easy, especially in teams or legacy projects.
5. Test Your Setup Thoroughly:
Once everything is set up, do a quick check to ensure all components are working properly:
python3 --version
pip3 --version
which python3
which pip3
Also test running a simple Python script:
echo "print('Python is working!')" > test.py
python3 test.py
6. Always Keep Python Updated:
Python evolves rapidly. Staying updated not only gives you access to new features but also includes important security patches and performance improvements.
On macOS:
brew upgrade python
On Ubuntu:
sudo apt update
sudo apt upgrade python3
Keep in mind that upgrading system Python versions directly (especially on Linux) can sometimes break system tools. That’s why using pyenv
or virtual environments is considered safer.
You can also visit the site: techonboom for more information.