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?
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
ln: /usr/local/bin/python: No such file or directory
on M1 Monterey 12.3 –
Kerge You can use symbolic link:
ln -s -f /usr/local/bin/python3 /usr/local/bin/python
ln: /usr/local/bin/python: No such file or directory
on M1 Monterey 12.3 –
Kerge 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
© 2022 - 2024 — McMap. All rights reserved.
python
to point topython3
. what is wrong with just typingpython3
? – Unjust