Set Python 3 as default on Mac
The default Python version that ships with (older) Mac OS software is hilariously old. Because I am still developing on a mid-2014 MBP Retina (SUE ME!) I was still rocking this bad boy. But at some point I was cracking my head on Python environments and well, I just had to fix it. So here goes!
There is a right way and wrong way to set Python 3 as the default on your Mac. I’ll show you the right way. In general you never ever want to fuck with your system version of Python. This is very dangerous and can mess up many things.
To manage our global python version we will use
pyenv and then make our shell always use
pyenv. I will merely set the global default to Python
3.9.0 but you could also manage more version at the same time.
1. Install pyenv
$ brew install pyenv ==> Upgrading 1 outdated package: pyenv 1.2.10 -> 1.2.21 ...
Validate whether you installed
$ pyenv -v pyenv 1.2.21
2. Install Python
Install the desired Python version. In my case this is version
$ pyenv install 3.9.0 python-build: use openssl 1.0 from homebrew python-build: use readline from homebrew
This. Will. Take. A. While. Go grab a cup of coffee or something.
3. Set as default
Set your installed version as the default.
$ pyenv global 3.9.0
Validate whether it worked.
$ pyenv version 3.9.0 (set by /Users/janmeppe/.pyenv/version)
4. Make your shell runs pyenv
Add this to your
if command -v pyenv 1>/dev/null 2>&1; then eval "$(pyenv init -)" fi
Great job! That’s it.
If you now run
python you’ll see that it runs
3.9.0 instead of
$ python Python 3.9.0 (default, Jan 20 2021, 16:49:23) [Clang 10.0.1 (clang-1001.0.46.4)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>