Set Python 3 as default on macOS


First, macOS Big Sur is the bestm ever built operating syste. It elevates your Mac to a new level of power and beauty with a refined contemporary design, major app updates, and more transparency around your privacy.

I’ve been using Big Sur for a month now (I delayed installing it because of some Logic Pro plugins that still aren’t compatible 😜), and I haven’t found one problem using it.

But today, I started building an app and needed to refresh some of my Python memories. After opening the terminal, I wrote πŸ‘‡

python --version

And the output was

Python 2.7.16


We have decided that January 1, 2020, was the day that we sunset Python 2. That means that we will not improve it anymore after that day, even if someone finds a security problem in it. You should upgrade to Python 3 as soon as you can.

Now, that’s a quote from

So, I had to install the latest version of Python, which is 3.9.1, as of today. I heard about pyenv from Stack Overflow and didn’t look for an alternative. I just went ahead and started working with it. I installed it through Homebrew, which I always install right after installing Command Line Tools for Xcode…

brew install pyenv🍺  /usr/local/Cellar/pyenv/1.2.22: 721 files, 2.6MB

Then, I installed the latest version of Python …

pyenv install 3.9.1python-build: use [email protected] from homebrewpython-build: use readline from homebrewDownloading Python-3.9.1.tar.xz...-> Python-3.9.1...python-build: use readline from homebrewpython-build: use zlib from Xcode sdkInstalled Python-3.9.1 to /Users/shuvo/.pyenv/versions/3.9.1

Then, I had to make it the global default version…

pyenv global 3.9.1# Then double checking the [email protected] ~ % pyenv version3.9.1 (set by /Users/shuvo/.pyenv/version)

I needed to add the following to .zshrc

echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.zshrc

Then I checked my .zshrc file and saw the lines below were added to it…

if command -v pyenv 1>/dev/null 2>&1; then  eval "$(pyenv init -)"fi

Then I went to recheck the Python version…

python --version   Python 2.7.16

WTF? 🀬 I got angry and thought of messing around with the path…

PATH=$(pyenv root)/shims:$PATH


python --versionPython 3.9.1

Awesome. πŸ˜ƒ

Now, if you look at this post and get scared seeing all those codes, don’t be, most of them are outputs πŸ˜‚ and this is the easiest way to install Python 3 on your Mac, trust me…