How to set Python3 as default in MacOS Monterey (Macbook Air M1)?
Asked Answered
S

3

6

Monterey(M1) has python2 and python3 preinstalled. But the python2 is set as default, I want to change it to python3. How to change the default version to python3? enter image description here

enter image description hereIn my Macbook Air having

Samal answered 9/1, 2022 at 13:29 Comment(3)
not sure if it would break some existing functionality under the hood by changing python to point to python3. what is wrong with just typing python3?Unjust
you would need to add symbolic(as suggested by Saliou DJIBRILA) and then export that. These two posts will give you some more details python3 before python2 and symbolic linkTeage
Please do not upload images of code/errors/text when asking a question.Stretto
A
15

If you are on Mac M1

Steps

1. $ brew install python
2. $ sudo ln -s -f /opt/homebrew/bin/python3 /usr/local/bin/python
3. Restart your terminal.
4. $ python --version

If you are on Intel Mac

Steps

1. $ brew install python
2. $ ln -s -f /usr/local/bin/python3.<your version> /usr/local/bin/python
3. Close Terminal and test version 
4. $ python --version
Angelineangelique answered 15/3, 2022 at 16:56 Comment(1)
ln: /usr/local/bin/python: No such file or directory on M1 Monterey 12.3Kerge
F
4

You can use symbolic link: ln -s -f /usr/local/bin/python3 /usr/local/bin/python

Frum answered 9/1, 2022 at 13:59 Comment(3)
permission denied?....Samal
Doesn't work: ln: /usr/local/bin/python: No such file or directory on M1 Monterey 12.3Kerge
This is the only solution that worked in my case, thanksDromond
R
2

From the information provided it is not possible to say if /usr/bin/python is already a symlink. You can check all the python versions in that directory and see if it is a symlink or not.

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

If python is an existing symlink

In the case that python is a symlink, you should be able to change the symlink to link to python3 as already suggested here, -s for soft, -f for force to overwrite an existing symlink.

ln -sf /usr/bin/python3 /usr/local/bin/python

If the operation is not permitted you will need to create it as root. If this is good solution I do not know, so use my answer with precaution.

sudo -i
ln -sf /usr/bin/python3 /usr/local/bin/python

Check if the right version is recognised

where python
python -V

From MacOS Monterey 12.3

From MacOS Monterey Version 12.3, python2 is no longer preinstalled, and is shipped with Python 3.8.9. Therefore python is not in use and a symlink can be used without concerns regarding python2.

python -V
zsh: command not found: python
python2 -V
zsh: command not found: python2
python3 -V
Python 3.8.9
Rossy answered 24/5, 2022 at 11:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.