Running into the “zsh: command not found: python” error on macOS Monterey 12.3 when using Python 3.10 with Atom IDE and the atom-python-run 0.9.7 package? This issue often occurs because macOS 12.3 removed the pre-installed Python 2, and the python
command no longer points to python3
. Additionally, the atom-python-run package may incorrectly call python
instead of python3
. Here’s a simple guide to fix it.
Why This Error Happens
Starting with macOS Monterey 12.3, Apple removed the default Python 2 installation, causing commands expecting python
to fail if Python 3 is installed. The atom-python-run package in Atom IDE may still use python
instead of python3
, leading to the error. Let’s resolve this step-by-step.
Steps to Fix the “zsh: command not found: python” Error
1. Verify Python 3.10 Installation
Ensure Python 3.10 is installed correctly.
- Open Terminal and run:
python3 --version
- If it shows
Python 3.10.x
, Python is installed. If not, install it via Homebrew:brew install python@3.10
- Confirm the installation path:
which python3
This typically returns/opt/homebrew/bin/python3
(for M1/M2 Macs) or/usr/local/bin/python3
(for Intel Macs).
2. Create an Alias for Python
Since macOS expects python3
but Atom’s atom-python-run may call python
, create an alias to map python
to python3
.
- Open Terminal and edit the zsh configuration:
nano ~/.zshrc
- Add this line at the end (use the path from
which python3
):alias python=/opt/homebrew/bin/python3
- Save (Ctrl + X, then Y, then Enter) and reload the shell:
source ~/.zshrc
- Test the alias:
python --version
It should displayPython 3.10.x
.
3. Update Atom’s atom-python-run Settings
The atom-python-run package may still call python
instead of python3
. Update its settings to fix this.
- Open Atom IDE.
- Go to
Atom > Preferences > Packages
. - Search for
atom-python-run
and click Settings. - In the Command field, change
python
topython3
or the full path (e.g.,/opt/homebrew/bin/python3
). - Save the settings and restart Atom.
4. Alternative: Use a Symbolic Link
If the alias doesn’t work for atom-python-run, create a symbolic link to make python
point to python3
.
- Run in Terminal:
sudo ln -s /opt/homebrew/bin/python3 /usr/local/bin/python
- Verify:
python --version
This ensurespython
runs Python 3.10 without relying on zsh settings.
5. Optional: Use pyenv for Python Version Management
To manage multiple Python versions and avoid conflicts, use pyenv
.
- Install pyenv via Homebrew:
brew install pyenv
- Install Python 3.10:
pyenv install 3.10.3
- Set it as the global version:
pyenv global 3.10.3
- Update your zsh profile:
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc echo 'eval "$(pyenv init -)"' >> ~/.zshrc source ~/.zshrc
Common Issues and Fixes
- Alias not working after restart: Ensure the alias is in
~/.zshrc
and runsource ~/.zshrc
after changes. - atom-python-run still fails: Double-check the package settings to ensure
python3
or the full path is specified. - PATH issues: Add Python to your PATH manually:
echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zshrc source ~/.zshrc
Troubleshooting Table
Issue | Solution |
---|---|
python3 not found | Install Python via brew install python@3.10 |
Alias not persisting | Add alias to ~/.zshrc and run source ~/.zshrc |
atom-python-run uses python | Update package settings to use python3 |
Multiple Python versions | Use pyenv to manage versions |
Helpful Resource
For more on managing Python environments, visit pyenv’s official guide. It’s a great tool for handling multiple Python versions on macOS!