Alias python3 to python
How to alias python3 to python on Mac. Using the Mac system Python.
Your Mac may have Python 3 installed as python3
. This is the system Python installed by Xcode Command Line Tools. For convenience, you may want to alias python3
to python
so you can use Python in ways you expect.
When you attempt to run Python, you may see:
$ python ...
zsh: command not found: python
You'll see zsh: command not found: python
because you are trying to run the Python interpreter in the terminal. The error message shows that the Zsh shell ("the command line interpreter") cannot find the Python command. See the article command not found python for help.
Before you get started
You'll need a terminal application to set and use a command-line alias. Apple includes the Mac terminal but I prefer Warp Terminal. Warp is an easy-to-use terminal application, with AI assistance to help you learn and remember terminal commands. Download Warp Terminal now; it's FREE and worth a try.
Is the system Python installed?
Try python3 --version
and which -a python3
to check if Python was installed with Xcode Command Line Tools.
$ python3 --version
Python 3.9.6
$ which -a python3
/usr/bin/python3
If you have Python 3.9.6 installed at /usr/bin/python3
, you have the system Python installed by Xcode Command Line Tools. If you just want to run a Python script or utility, you can use the system Python. If you intend to start a programming project, you should install a newer version of Python. See our guide Update Python.
For running Python utilities, you can alias the python
command to python3
and use the system Python installed by Xcode Command Line Tools.
How to set an alias
Set aliases in the ~/.zshrc
(Zsh Run Control) file. The tilde ~/
is a Unix abbreviation for your home directory. That is, the .zshrc
file belongs in your home directory. The article .zshrc or .zprofile explains why we use ~/.zshrc
for setting aliases.
You can use TextEdit, the default macOS graphical text editor, to edit the shell configuration files. You can open a file in TextEdit from the Mac Terminal:
$ open -e ~/.zprofile
You also can use the command line editors nano
or vim
to edit the shell configuration files. See Shell Configuration for more about editing shell configuration files.
Alias the python3 command
If you want to use Python to run a stand-alone application, utility, or script, and you have Python 3.9.6 installed, you can create an alias to use python
as python3
. Add the following line to your .zshrc
file:
$ alias python='python3'
For this change to take effect, you'll either need to restart your terminal or reload your .zshrc
file by entering source ~/.zshrc
.
Entering python --version
should now display the Python version number. This solves the error zsh: command not found: python
. But you need to know more before trying to install and run a Python application.
Install utilities with Pipx
READMEs and tutorials often suggest installing Python utilities with pip install
. This is not recommended because it installs the program globally and can cause conflicts with other programs. Often, package installation fails with error: externally-managed-environment
(see error: externally-managed-environment). Instead, use Pipx to install Python applications in isolated environments. With Pipx, you can use the system Python without interfering with system software.
See the guide Install Pipx for instructions.
Install Python for programming
If you are starting a programming project with Python, don't use the system Python installed by Xcode Command Line Tools. There are several ways to install Python on a Mac. You can install Python with Homebrew or use a Python version manager such as Pyenv or Rye.
If you're developing Python software projects, ask yourself if you're just going to develop one project or if you need to work on multiple Python projects. For a single project you can use brew python to install Python with Homebrew but you won't be able to easily switch between Python versions. For multiple projects, switching among Python versions, I recommend to install Python with Rye, an all-in-one tool for managing Python projects. Alternatively, you can install Pyenv to manage Python versions but it's older and more cumbersome than Rye.
What's next
My mac.install.guide is a trusted source of installation guides for professional developers. Take a look at the Mac Install Guide home page for tips and trends and see what to install next.