[MacOS] Change default Python to Python3 - HOW?

[MacOS] Change default Python to Python3 - HOW?

With default, Any new purchased Mac comes with Python 2.version.

But, I think, and believe that most of us have long back started to work with Python-3 and it is very annoying to run python3 every time instead of python in terminal.

As of Now, default Python[which comes in Mac] is depreciated and no longer supported by Python itself.

Below are the steps - how to do this

1) Open the terminal (bash or zsh) whatever shell you are using.

2) Install python-3 using Homebrew (brew.sh).

brew install python

3) Look where it is installed.

ls -l /usr/local/bin/python*

4) The output is something like this:

lrwxr-xr-x  1 samtechsolutions  admin  24 Nov  3 16:29 /usr/local/bin/python -> /usr/local/bin/python3.9
lrwxr-xr-x  1 samtechsolutions  admin  39 Oct 10 00:43 /usr/local/bin/python-build -> ../Cellar/pyenv/1.2.21/bin/python-build
lrwxr-xr-x  1 samtechsolutions  admin  40 Oct 28 20:58 /usr/local/bin/python3 -> ../Cellar/python@3.9/3.9.0_1/bin/python3
lrwxr-xr-x  1 samtechsolutions  admin  47 Oct 28 20:58 /usr/local/bin/python3-config -> ../Cellar/python@3.9/3.9.0_1/bin/python3-config
lrwxr-xr-x  1 samtechsolutions  admin  42 Oct 28 20:58 /usr/local/bin/python3.9 -> ../Cellar/python@3.9/3.9.0_1/bin/python3.9
lrwxr-xr-x  1 samtechsolutions  admin  49 Oct 28 20:58 /usr/local/bin/python3.9-config -> ../Cellar/python@3.9/3.9.0_1/bin/python3.9-config

5) Change the default python symlink to the version you want to use from above.

Note that, we only need to choose the one which states

 ...../usr/local/bin/python3.version

[NOTE] : Please avoid using the ones that end with --config or python3.version.0_1 OR python3. version-config.

6) Below command shows how it should be done:

ln -s -f /usr/local/bin/python3.9 /usr/local/bin/python

7) Close the current terminal session or keep it that way and instead open a new terminal window (not tab).

8) Run this:

python --version

You will get this Output/Result:

Python 3.9.0

[which ever is the latest updated Python.version]

In Less than 10 steps, You can change your default Python to Python3.version

That's it.

Happy coding!!