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

6
  • as per the top answer of stackoverflow.com/questions/18425379/… this is not advised and could break some things Commented May 21, 2020 at 18:59
  • Does this answer your question? How to set Python's default version to 3.x on OS X? Commented May 21, 2020 at 18:59
  • @KevinWang I tried alias way too as I mentioned in my question it didn't work. Commented May 21, 2020 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? Commented May 21, 2020 at 19:06
  • @KevinWang Yes you're correct Commented May 21, 2020 at 19:26

1 Answer 1

9

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

Sign up to request clarification or add additional context in comments.

1 Comment

This saved me time today.. Thanks for the sleek answer!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.