Jeena
Jeena

Reputation: 4293

How to set Python3 as a default python version on Mac?

Is there a way to set the Python 3.8.3 as the default Python version on macOS Catalina -- version 10.15.2?

Steps I have done:

  1. Look where it is installed.
ls -l /usr/local/bin/python*

The output I got is something like this:

lrwxr-xr-x  1 jeena  admin  36 Mar 20  2019 /usr/local/bin/python -> ../Cellar/python@2/2.7.16/bin/python
lrwxr-xr-x  1 jeena  admin  39 May 20 12:43 /usr/local/bin/python-build -> ../Cellar/pyenv/1.2.18/bin/python-build
lrwxr-xr-x  1 jeena  admin  43 Mar 20  2019 /usr/local/bin/python-config -> ../Cellar/python@2/2.7.16/bin/python-config
lrwxr-xr-x  1 jeena  admin  37 Mar 20  2019 /usr/local/bin/python2 -> ../Cellar/python@2/2.7.16/bin/python2
lrwxr-xr-x  1 jeena  admin  44 Mar 20  2019 /usr/local/bin/python2-config -> ../Cellar/python@2/2.7.16/bin/python2-config
lrwxr-xr-x  1 jeena  admin  39 Mar 20  2019 /usr/local/bin/python2.7 -> ../Cellar/python@2/2.7.16/bin/python2.7
lrwxr-xr-x  1 jeena  admin  46 Mar 20  2019 /usr/local/bin/python2.7-config -> ../Cellar/python@2/2.7.16/bin/python2.7-config
lrwxr-xr-x  1 root   wheel  69 May 20 12:22 /usr/local/bin/python3 -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/python3
lrwxr-xr-x  1 root   wheel  76 May 20 12:22 /usr/local/bin/python3-config -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/python3-config
lrwxr-xr-x  1 root   wheel  71 May 20 12:22 /usr/local/bin/python3.8 -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8
lrwxr-xr-x  1 root   wheel  78 May 20 12:22 /usr/local/bin/python3.8-config -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8-config
lrwxr-xr-x  1 jeena  admin  37 Mar 20  2019 /usr/local/bin/pythonw -> ../Cellar/python@2/2.7.16/bin/pythonw
lrwxr-xr-x  1 jeena  admin  38 Mar 20  2019 /usr/local/bin/pythonw2 -> ../Cellar/python@2/2.7.16/bin/pythonw2
lrwxr-xr-x  1 jeena  admin  40 Mar 20  2019 /usr/local/bin/pythonw2.7 -> ../Cellar/python@2/2.7.16/bin/pythonw2.7
  1. Change the default python symlink to the version I want to use from above:
ln -s -f /usr/local/bin/python3.8 /usr/local/bin/python2.7

Then I checked the version again:

python --version

And I got it as --> Python 2.7.16

I also tried alias python="/usr/bin/python3.8" but sadly it's still Python 2.7.16

Upvotes: 3

Views: 12955

Answers (1)

Philippe
Philippe

Reputation: 26422

I think you can run the following commands :

rm /usr/local/bin/python
ln -s /usr/local/bin/python3.8 /usr/local/bin/python

And in your ~/.zshrc or ~/.bashrc, put

export PATH=/usr/local/bin:$PATH

Then start a new terminal to test

echo $PATH

to make sure /usr/local/bin is before /usr/bin

Upvotes: 9

Related Questions