3

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

Jeena
  • 4,193
  • 3
  • 9
  • 19
  • as per the top answer of https://stackoverflow.com/questions/18425379/how-to-set-pythons-default-version-to-3-x-on-os-x this is not advised and could break some things – Kevin Wang May 21 '20 at 18:59
  • Does this answer your question? [How to set Python's default version to 3.x on OS X?](https://stackoverflow.com/questions/18425379/how-to-set-pythons-default-version-to-3-x-on-os-x) – Kevin Wang May 21 '20 at 18:59
  • @KevinWang I tried ```alias``` way too as I mentioned in my question it didn't work. – Jeena May 21 '20 at 19:01
  • so `> /usr/bin/python3.8` correctly starts the python3 REPL, but `> alias python="/usr/bin/python3.8"` followed by `> python` starts the python2 REPL? – Kevin Wang May 21 '20 at 19:06
  • @KevinWang Yes you're correct – Jeena May 21 '20 at 19:26
  • that is strange indeed. What shell are you using? Can you edit the question and copy-paste from shell exactly the commands and outputs you ran when you tried the aliasing? – Kevin Wang May 21 '20 at 20:34

1 Answers1

8

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

Philippe
  • 20,025
  • 2
  • 23
  • 32