free-tech

How to set default python as python3 on macOS ?


Python version 2 it is the default python version on MacOs.  But most of time this days we start using python3 on our last projects and it is annoying every time we should specify the python 3 version in every command line we write. in this article we will show how to  set python3 as the default python version on your MacOS.

1 - Open the terminal :

Install python3 using Homebrew

brew install python

Output:
Python has been installed as  /opt/homebrew/bin/python3

2 - Check Where installed:

ls -l /opt/homebrew/bin/python*

Output:
lrwxr-xr-x  1 soufianlagnaoui  admin  40 Nov 29 01:34 /opt/homebrew/bin/python3 -> ../Cellar/[email protected]/3.10.8/bin/python3

lrwxr-xr-x  1 soufianlagnaoui  admin  47 Nov 29 01:34 /opt/homebrew/bin/python3-config -> ../Cellar/[email protected]/3.10.8/bin/python3-config

lrwxr-xr-x  1 soufianlagnaoui  admin  43 Nov 29 01:34 /opt/homebrew/bin/python3.10 -> ../Cellar/[email protected]/3.10.8/bin/python3.10

lrwxr-xr-x  1 soufianlagnaoui  admin  50 Nov 29 01:34 /opt/homebrew/bin/python3.10-config -> ../Cellar/[email protected]/3.10.8/bin/python3.10-config

3 - Change the default python symlink :

ln -s -f /opt/homebrew/bin/python3.10 /usr/local/bin/python

4 - Check the new python version:

Close the current terminal session and open a one and execute this command line:
python --version
Output:
Python 3.10

And that's it.

#python #python3