If you are a Mac OSx user, you will frequently come across installing different packages via terminal. To install python packages, you will need the pip command. By default, Mac OS comes with an older version of python 2.7 due to dependencies. The latest version of packages cannot be downloaded using the pip associated with the old python version.
You might be thinking of removing python 2.7 and replacing it with the new one. It is highly recommended not to remove the older version of python as it will affect the functionality of different in-built apps.
Here, you will learn of a simple way to use the latest version of python without removing python 2.7. Install the latest version of python
First things first, you will need the latest version of python. You can download it from the Python website or simply use Homebrew for the installation.
brew install python
You can verify the installation by typing
python -V
Here is the most important part. You can now set up a default alias for the latest version of python. That way, you can enjoy the latest version of python without having to remove the older one.
Go to your shell config file and add an alias. If you use zsh or default bash shell, you can simply create an alias by adding the following line to your config file:
alias python=/usr/local/bin/python3
You will also need to create an alias for pip
alias pip=/usr/local/bin/pip3
You can simply close your terminal and restart it to use the latest version of Python and pip.
You can check where your python and pip are aliased by simply running in your terminal:
which python
which pip
One drawback of this method is that you will need to manually update the config file when there is a newer version of Python 🐍 .
Check your Homebrew path first
The /usr/local/bin path above is correct for Intel Macs. On Apple Silicon, Homebrew installs to /opt/homebrew instead, so the alias needs to match:
alias python=/opt/homebrew/bin/python3
alias pip=/opt/homebrew/bin/pip3
Rather than guessing, ask Homebrew where it put things:
brew --prefix python
Better still, skip the hardcoded path entirely and alias to whatever python3 resolves to on your PATH:
alias python=python3
alias pip=pip3
That survives both Homebrew upgrades and a move to a new Mac.
Where to put the alias
It depends on your shell. macOS has shipped zsh as the default since Catalina:
# zsh
> echo 'alias python=python3' >> ~/.zshrc
> source ~/.zshrc
# bash
> echo 'alias python=python3' >> ~/.bash_profile
> source ~/.bash_profile
source re-reads the config so you don’t have to close the terminal.
The catch with aliases
This is the part most guides skip. A shell alias only applies to commands you type interactively. It does not affect:
- Scripts you run (
./script.py,bash deploy.sh) - Shebang lines (
#!/usr/bin/env python) - Anything a build tool, Makefile, or editor launches
- Non-interactive shells, including most CI runners
So an alias makes your typing convenient. It does not change what “python” means to the rest of the system — and that’s deliberate, because changing it globally is what breaks things.
What about Python 2?
If you’re on macOS Monterey (12.3) or newer, the question is moot: Apple removed the bundled Python 2.7 entirely. The warning about not deleting it applies to older machines. On a current Mac, python simply isn’t there until you provide it — which is why the alias is useful rather than dangerous.
The better long-term answer: pyenv
Aliases stop being enough the moment two projects need different Python versions. pyenv handles that properly:
> brew install pyenv
> pyenv install 3.12.4
> pyenv global 3.12.4
Add pyenv’s initialisation to your shell config:
> echo 'eval "$(pyenv init -)"' >> ~/.zshrc
Now python is 3.12.4 everywhere — scripts and shebangs included, not just interactive commands. And pyenv local 3.10.13 inside a project directory pins that one project to a different version via a .python-version file, with no aliases involved.
Verify what you’ve got
> which python
> python -V
> which pip
> pip -V
If which python prints the path to your alias target (or a pyenv shim), you’re set. Note that pip -V also prints which interpreter it will install into — worth checking when packages seem to install but then can’t be imported, which is nearly always a case of pip and python pointing at different installations.
Once this is sorted, the next thing worth setting up is a virtual environment per project so package installs stay isolated.