Many Have you ever installed Python3.x on your computer, typed python in the terminal, and gotten a frustrating command not found error, only to realize python3 works just fine?
$python bash: python: command not found $ $python3 Python 3.12.8 (v3.12.8:2dc476bcb91, Dec 3 2024, 14:43:19) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>
If this has
happened to you, don’t worry, you’re not alone! This is a common issue,
especially for beginners or developers.
Why Is There a Difference Between python and python3?
Back in the day, running python in the terminal would start Python 2, the older (now outdated) version of Python. When Python 3 was released, it introduced changes that weren’t fully compatible with Python 2. To avoid breaking existing scripts, most systems kept:
· python for Python 2 installation
· python3 for Python 3 installation
Over time, Python 2 was officially discontinued (as of 2020), and many modern systems now only install Python 3 by default, but they don’t always set up python as a shortcut. That’s why you might see:
· python3 works (because it’s explicitly Python 3).
· python fails (because the system doesn’t automatically link it to Python 3).
How to Make python Run Python 3?
If you want python to just work, create a simple alias to python3 command line tool. You can tell your terminal to treat python as python3 by adding an alias to your shell configuration file.
echo 'alias python=python3' >> ~/.bashrc && source ~/.bashrc
If you're on macOS and use ~/.bash_profile instead, replace .bashrc with .bash_profile
For Zsh (macOS default shell):
echo 'alias python=python3' >> ~/.zshrc && source ~/.zshrc
After running this, check that it works:
$python --version Python 3.12.8 $ $python3 --version Python 3.12.8
Now, python and python3 will do the same thing!
The difference between python and python3 is an old leftover from earlier versions, but it’s easy to deal with. If you want to use python in python3 installation, the easiest fix is to create an alias.
No comments:
Post a Comment