DEV Community

loading...

Change Python Version Mac How to set Python3 as a default python version on MacOS?

malwarebo profile image Irfan Updated on ・2 min read

By default MacOS ships with Python-2.-. But, I guess most of us have long back started to work with Python-3 and it is very irritating to run python3 every time instead of python in terminal. Here is how to do this.

Open the terminal (bash or zsh) whatever shell you are using.

Install python-3 using Homebrew (https://brew.sh).

brew install python

Look where it is installed.

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

The output is something like this:

lrwxr-xr-x  1 irfan  admin  34 Nov 11 16:32 /usr/local/bin/python3 -> ../Cellar/python/3.7.5/bin/python3
lrwxr-xr-x  1 irfan  admin  41 Nov 11 16:32 /usr/local/bin/python3-config -> ../Cellar/python/3.7.5/bin/python3-config
lrwxr-xr-x  1 irfan  admin  36 Nov 11 16:32 /usr/local/bin/python3.7 -> ../Cellar/python/3.7.5/bin/python3.7
lrwxr-xr-x  1 irfan  admin  43 Nov 11 16:32 /usr/local/bin/python3.7-config -> ../Cellar/python/3.7.5/bin/python3.7-config
lrwxr-xr-x  1 irfan  admin  37 Nov 11 16:32 /usr/local/bin/python3.7m -> ../Cellar/python/3.7.5/bin/python3.7m
lrwxr-xr-x  1 irfan  admin  44 Nov 11 16:32 /usr/local/bin/python3.7m-config -> ../Cellar/python/3.7.5/bin/python3.7m-config

Change the default python symlink to the version you want to use from above.
Note that, we only need to choose the one that end with python3.*. Please avoid using the ones' that end with config or python3.*m or python3.*m-config.

Below command shows how it should be done:

ln -s -f /usr/local/bin/python3.7 /usr/local/bin/python

Close the current terminal session or keep it that way and instead open a new terminal window (not tab). Run this:

python --version

You will get this:

Python 3.7.5

Hah! That's it. Happy coding!!

Discussion (69)

pic
Editor guide
Collapse
tedonmain profile image
tedro • Edited

Worked! Thanks!

I'm not saying anyone would want to install Python 3 without brew, but if they did, pip3 gets installed:
$ pip3 --version
pip 19.2.3 from /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8)
$ pip3 install --upgrade pip
Collecting pip
Downloading files.pythonhosted.org/packages/54... (1.4MB)
|████████████████████████████████| 1.4MB 1.7MB/s
Installing collected packages: pip
Found existing installation: pip 19.2.3
Uninstalling pip-19.2.3:
Successfully uninstalled pip-19.2.3
Successfully installed pip-20.0.2

$ which pip
/Library/Frameworks/Python.framework/Versions/3.8/bin/pip

Now, Irfan's handy command:
sudo ln -s -f /usr/local/bin/python3.8 /usr/local/bin/python

close/open terminal

$ python --version
Python 3.8.2

yay Irfan!

Collapse
apoorveesinha profile image
APOORVEE SINHA

Hey! I tried following your above-mentioned method .. but I don't know how the path is different ...Although this method worked but will that path create any problem later on?
On my mac
which pip results in
/usr/local/bin/pip
instead of
/Library/Frameworks/Python.framework/Versions/3.8/bin/pip

apoorveesinha@Apoorvees-Air ~ % python --version
Python 2.7.16
apoorveesinha@Apoorvees-Air ~ % python3 --version
Python 3.8.2
apoorveesinha@Apoorvees-Air ~ % pip3 --version
pip 19.2.3 from /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8)
apoorveesinha@Apoorvees-Air ~ % pip3 install --upgrade pip
Collecting pip
Downloading files.pythonhosted.org/packages/54... (1.4MB)Installing collected packages: pip
Found existing installation: pip 19.2.3
Uninstalling pip-19.2.3:
Successfully uninstalled pip-19.2.3
Successfully installed pip-20.0.2
apoorveesinha@Apoorvees-Air ~ % which pip
/usr/local/bin/pip
apoorveesinha@Apoorvees-Air ~ % which pip
/usr/local/bin/pip
apoorveesinha@Apoorvees-Air ~ % sudo ln -s -f /usr/local/bin/python3.8 /usr/local/bin/python
Password:
apoorveesinha@Apoorvees-Air ~ %

close/open terminal

apoorveesinha@Apoorvees-Air ~ % python --version
Python 3.8.2
apoorveesinha@Apoorvees-Air ~ % python3 --version
Python 3.8.2

Please help!

Collapse
tedonmain profile image
tedro

I’m happy to read that the steps worked for you. The subject of the post I responded to was setting up Python 3 to be the default. From what I can tell, that is what you now have. My goal was to show how I did this directly versus using a package manager like Brew, but not everyone is comfortable with this approach. It looks like you are good to go if you want to work in Python 3 by default.

Collapse
garciatavo profile image
Tav0

export PATH=/usr/local/opt/python3/libexec/bin:$PATH

Thread Thread
crimsonkida profile image
CrimsonKidA

This worked for me! THANK YOU! :D

Collapse
nishu_2811 profile image
Nishant Ranjan

Thank you for sharing. It saved my day.

Collapse
tedonmain profile image
tedro

-ha! good to hear. I receive a message like yours about once per month. seems like a niche crowd we are in, hoping to avoid brew on our mac. it was exactly what I needed also.

Collapse
elpidabantra profile image
elpidabantra

Oh god! Thank you so much for your answer, I had tried everything and I was going crazy with that thing, I did the same with Python 3.7 and I finally see:
$ python --version
Python 3.7.8

Collapse
tedonmain profile image
tedro

Great! I'm happy it help you.

Collapse
ocalde profile image
Oscar Calderon

Hello Irfan, thanks for the quick tutorial. I have Catalina, and it didn't work for me. I was able to install python using brew, but even if I create the symlink in /usr/local/bin, it seems it is taking the symlink in /usr/bin which points to python2.7.

When I try to change that symlink, I get the message ln: python: Operation not permitted

Any ideas about what can be done?

Collapse
malwarebo profile image
Irfan Author

Hi, sorry for late reply.

What is the output of this command you get?

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

Collapse
monmoscovitz profile image
Mon Moscovitz

Output seem like this (Catalina - 10.15.3)
lrwxr-xr-x 1 hoangson admin 24 Feb 21 10:40 /usr/local/bin/python -> /usr/local/bin/python3.7
lrwxr-xr-x 1 hoangson admin 34 Dec 17 20:48 /usr/local/bin/python3 -> ../Cellar/python/3.7.5/bin/python3
lrwxr-xr-x 1 hoangson admin 41 Dec 17 20:48 /usr/local/bin/python3-config -> ../Cellar/python/3.7.5/bin/python3-config
lrwxr-xr-x 1 hoangson admin 36 Dec 17 20:48 /usr/local/bin/python3.7 -> ../Cellar/python/3.7.5/bin/python3.7
lrwxr-xr-x 1 hoangson admin 43 Dec 17 20:48 /usr/local/bin/python3.7-config -> ../Cellar/python/3.7.5/bin/python3.7-config
lrwxr-xr-x 1 hoangson admin 37 Dec 17 20:48 /usr/local/bin/python3.7m -> ../Cellar/python/3.7.5/bin/python3.7m
lrwxr-xr-x 1 hoangson admin 44 Dec 17 20:48 /usr/local/bin/python3.7m-config -> ../Cellar/python/3.7.5/bin/python3.7m-config

Thread Thread
malwarebo profile image
Irfan Author

It seems you already have 3.7 as a default version. See first line of the output.

Thread Thread
vincentfeng0101 profile image
Vincent

hello sir, I have this output with command: ls -l /usr/local/bin/python*, but when I type python --version, output is still python2. could you please help me

lrwxr-xr-x 1 djf admin 24 Mar 21 15:40 /usr/local/bin/python -> /usr/local/bin/python3.7
lrwxr-xr-x 1 djf admin 34 Jun 20 2019 /usr/local/bin/python3 -> ../Cellar/python/3.7.3/bin/python3
lrwxr-xr-x 1 djf admin 41 Jun 20 2019 /usr/local/bin/python3-config -> ../Cellar/python/3.7.3/bin/python3-config
lrwxr-xr-x 1 djf admin 36 Jun 20 2019 /usr/local/bin/python3.7 -> ../Cellar/python/3.7.3/bin/python3.7
lrwxr-xr-x 1 djf admin 43 Jun 20 2019 /usr/local/bin/python3.7-config -> ../Cellar/python/3.7.3/bin/python3.7-config
lrwxr-xr-x 1 djf admin 37 Jun 20 2019 /usr/local/bin/python3.7m -> ../Cellar/python/3.7.3/bin/python3.7m
lrwxr-xr-x 1 djf admin 44 Jun 20 2019 /usr/local/bin/python3.7m-config -> ../Cellar/python/3.7.3/bin/python3.7m-config

Thread Thread
malwarebo profile image
Irfan Author

Hey, what is your MacOS version?

Thread Thread
vincentfeng0101 profile image
Vincent

thank you for your reply, i have fix my problem.

Thread Thread
malwarebo profile image
Irfan Author

Awesome, glad that you fixed it.

Thread Thread
alt_blr_ceo profile image
Just Another Security Researcher

I'm on MacOS Catalina and it worked. Strange

Thread Thread
xianyang27200 profile image
xianyang27200

how did you fixed it please i have the same issue as yours 100%

Collapse
alexneville47 profile image
alexneville47 • Edited

I already have homebrew and python 3.7.8 installed and when i followed the steps you provided it still had python 2.7.16 instead of 3.7.8 and i followed every step any idea whats wrong? by the way im on the newest macOS because i just got this laptop a few days ago

Collapse
chashchindmitry profile image
Chashchin-Dmitry

dmitrij$ ln -s -f /usr/local/bin/python3.8.2 /usr/local/bin/python
ln: /usr/local/bin/python: Permission denied

Excuse me, how can I avoid or get permission?

Collapse
malwarebo profile image
Irfan Author

Hey could you try this first then run the command?

sudo chown -R $(whoami) /usr/local/bin/python

Collapse
bubasar profile image
Bubasar

Hi , Dmitry
Could you solve the problem you have above ? I have the same problem and if you managed to solve it pls share me your way ?

Collapse
malwarebo profile image
Irfan Author

Hey try this:

sudo chown -R $(whoami) /usr/local/python

then

ln -s -f /usr/local/bin/python3.8.2 /usr/local/bin/python

Thread Thread
bubasar profile image
Bubasar

That is worked Irfan. Thanks for your help .

Collapse
apoorveesinha profile image
APOORVEE SINHA

I have followed all the steps but python --version gives Python 2.7.16 as output. Please help.

ls -l /usr/local/bin/python*
lrwxr-xr-x 1 apoorveesinha admin 24 Mar 30 04:57 /usr/local/bin/python -> /usr/local/bin/python3.7
lrwxr-xr-x 1 apoorveesinha admin 34 Mar 30 04:55 /usr/local/bin/python3 -> ../Cellar/python/3.7.7/bin/python3
lrwxr-xr-x 1 apoorveesinha admin 41 Mar 30 04:55 /usr/local/bin/python3-config -> ../Cellar/python/3.7.7/bin/python3-config
lrwxr-xr-x 1 apoorveesinha admin 36 Mar 30 04:55 /usr/local/bin/python3.7 -> ../Cellar/python/3.7.7/bin/python3.7
lrwxr-xr-x 1 apoorveesinha admin 43 Mar 30 04:55 /usr/local/bin/python3.7-config -> ../Cellar/python/3.7.7/bin/python3.7-config
lrwxr-xr-x 1 apoorveesinha admin 37 Mar 30 04:55 /usr/local/bin/python3.7m -> ../Cellar/python/3.7.7/bin/python3.7m
lrwxr-xr-x 1 apoorveesinha admin 44 Mar 30 04:55 /usr/local/bin/python3.7m-config -> ../Cellar/python/3.7.7/bin/python3.7m-config
lrwxr-xr-x 1 root wheel 71 Mar 30 04:37 /usr/local/bin/python3.8 -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8
lrwxr-xr-x 1 root wheel 78 Mar 30 04:37 /usr/local/bin/python3.8-config -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8-config
apoorveesinha@Apoorvees-Air ~ % ln -s -f /usr/local/bin/python3.7 /usr/local/bin/python
apoorveesinha@Apoorvees-Air ~ % python --version

Python 2.7.16
apoorveesinha@Apoorvees-Air ~ % pip3 --version
pip 19.2.3 from /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8)

Collapse
malwarebo profile image
Irfan Author

Did you check after starting a new terminal session?

Collapse
apoorveesinha profile image
APOORVEE SINHA

Yes, I did.
Moreover, I tried following tedro's method above in the comment section.. but I don't know how the path is different ...Although this method worked but will that path create any problem later on?
On my mac
which pip results in
/usr/local/bin/pip
instead of
/Library/Frameworks/Python.framework/Versions/3.8/bin/pip

Last login: Thu Apr 16 18:09:08 on ttys000
apoorveesinha@Apoorvees-Air ~ % python --version
Python 2.7.16
apoorveesinha@Apoorvees-Air ~ % python3 --version
Python 3.8.2
apoorveesinha@Apoorvees-Air ~ % pip3 --version
pip 19.2.3 from /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8)
apoorveesinha@Apoorvees-Air ~ % pip3 install --upgrade pip
Collecting pip
Downloading files.pythonhosted.org/packages/54... (1.4MB)Installing collected packages: pip
Found existing installation: pip 19.2.3
Uninstalling pip-19.2.3:
Successfully uninstalled pip-19.2.3
Successfully installed pip-20.0.2
apoorveesinha@Apoorvees-Air ~ % which pip
/usr/local/bin/pip
apoorveesinha@Apoorvees-Air ~ % which pip
/usr/local/bin/pip
apoorveesinha@Apoorvees-Air ~ % sudo ln -s -f /usr/local/bin/python3.8 /usr/local/bin/python
Password:
apoorveesinha@Apoorvees-Air ~ %

close/open terminal

apoorveesinha@Apoorvees-Air ~ % python --version
Python 3.8.2
apoorveesinha@Apoorvees-Air ~ % python3 --version
Python 3.8.2

Please help!

Collapse
ariefbaidowi profile image
Bai

Hi, I have problem with my installation. I use OS X El Capitan (10.11.6).

$ ln -s -f /usr/local/bin/python3.7 /usr/local/bin/python
ln: /usr/local/bin/python: Permission denied
users-mbp:bin Bai$ ls -l /usr/local/bin/python*
lrwxr-xr-x 1 root wheel 68 Apr 23 00:34 /usr/local/bin/python -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python
lrwxr-xr-x 1 root wheel 75 Apr 23 00:34 /usr/local/bin/python-config -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python-config
lrwxr-xr-x 1 root wheel 69 Apr 23 00:34 /usr/local/bin/python2 -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python2
lrwxr-xr-x 1 root wheel 76 Apr 23 00:34 /usr/local/bin/python2-config -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python2-config
lrwxr-xr-x 1 root wheel 71 Apr 23 00:34 /usr/local/bin/python2.7 -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x 1 root wheel 78 Apr 23 00:34 /usr/local/bin/python2.7-config -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
lrwxr-xr-x 1 root wheel 69 Apr 23 01:21 /usr/local/bin/python3 -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/python3
lrwxr-xr-x 1 root wheel 76 Apr 23 01:21 /usr/local/bin/python3-config -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/python3-config
lrwxr-xr-x 1 root wheel 71 Apr 23 01:21 /usr/local/bin/python3.8 -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8
lrwxr-xr-x 1 root wheel 78 Apr 23 01:21 /usr/local/bin/python3.8-config -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8-config
lrwxr-xr-x 1 root wheel 69 Apr 23 00:34 /usr/local/bin/pythonw -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw
lrwxr-xr-x 1 root wheel 70 Apr 23 00:34 /usr/local/bin/pythonw2 -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2
lrwxr-xr-x 1 root wheel 72 Apr 23 00:34 /usr/local/bin/pythonw2.7 -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7

Can u help me to solve it ?

Collapse
fxgx99 profile image
C Martin • Edited

Hi I am having a similar problem but i just recently updated to MacOs Big sure and I have been trying to install aws cli and ran into this python version issue. Below is the output of ls -l /usr/local/bin/python*: however i am still getting Python 3.7.10 as my default and I will like to change that to python3.9

The first 10 lines of ls -l /usr/local/bin/python* is below :
rwxr-xr-x root admin 24 B Wed Apr 7 09:42:43 2021  python ⇒ /usr/local/bin/python3.9

rwxr-xr-x christian wheel 71 B Sun Nov 8 08:08:51 2015  python-32 ⇒ ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python-32

rwxr-xr-x christian wheel 75 B Sun Nov 8 08:08:51 2015  python-config ⇒ ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python-config

rwxr-xr-x christian wheel 69 B Sun Nov 8 08:08:51 2015  python2 ⇒ ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python2

rwxr-xr-x christian wheel 72 B Sun Nov 8 08:08:51 2015  python2-32 ⇒ ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python2-32

rwxr-xr-x christian wheel 76 B Sun Nov 8 08:08:51 2015  python2-config ⇒ ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python2-config

rwxr-xr-x christian wheel 71 B Sun Nov 8 08:08:51 2015  python2.7 ⇒ ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7

rwxr-xr-x christian wheel 74 B Sun Nov 8 08:08:51 2015  python2.7-32 ⇒ ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-32

rwxr-xr-x christian wheel 78 B Sun Nov 8 08:08:51 2015  python2.7-config ⇒ ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config

rwxr-xr-x root wheel 69 B Wed Apr 7 07:59:49 2021  python3 ⇒ ../../../Library/Frameworks/Python.framework/Versions/3.9/bin/python3

Collapse
malwarebo profile image
Irfan Author

Did you try this:

ln -s -f /usr/local/bin/python3.9 /usr/local/bin/python

Provided you have installed Python 3.9.

Collapse
srinivasaraog30 profile image
srinivasarao.gurram

Hi Irfan,
Can you help,

lrwxr-xr-x 1 sgurram admin 24 May 14 19:17 /usr/local/bin/python -> /usr/local/bin/python3.7
lrwxr-xr-x 1 sgurram admin 39 May 7 14:14 /usr/local/bin/python-build -> ../Cellar/pyenv/1.2.18/bin/python-build
lrwxr-xr-x 1 root wheel 75 May 14 16:28 /usr/local/bin/python-config -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python-config
lrwxr-xr-x 1 root wheel 69 May 14 16:28 /usr/local/bin/python2 -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python2
lrwxr-xr-x 1 root wheel 76 May 14 16:28 /usr/local/bin/python2-config -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python2-config
lrwxr-xr-x 1 root wheel 71 May 14 16:28 /usr/local/bin/python2.7 -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x 1 root wheel 78 May 14 16:28 /usr/local/bin/python2.7-config -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
lrwxr-xr-x 1 sgurram admin 34 May 14 16:26 /usr/local/bin/python3 -> ../Cellar/python/3.7.7/bin/python3
lrwxr-xr-x 1 sgurram admin 41 May 14 16:26 /usr/local/bin/python3-config -> ../Cellar/python/3.7.7/bin/python3-config
lrwxr-xr-x 1 sgurram admin 36 May 14 16:26 /usr/local/bin/python3.7 -> ../Cellar/python/3.7.7/bin/python3.7
lrwxr-xr-x 1 sgurram admin 43 May 14 16:26 /usr/local/bin/python3.7-config -> ../Cellar/python/3.7.7/bin/python3.7-config
lrwxr-xr-x 1 sgurram admin 37 May 14 16:26 /usr/local/bin/python3.7m -> ../Cellar/python/3.7.7/bin/python3.7m
lrwxr-xr-x 1 sgurram admin 44 May 14 16:26 /usr/local/bin/python3.7m-config -> ../Cellar/python/3.7.7/bin/python3.7m-config
lrwxr-xr-x 1 root wheel 69 May 14 16:28 /usr/local/bin/pythonw -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw
lrwxr-xr-x 1 root wheel 70 May 14 16:28 /usr/local/bin/pythonw2 -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2
lrwxr-xr-x 1 root wheel 72 May 14 16:28 /usr/local/bin/pythonw2.7 -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7

my version is mac os catalina 10.15.4
sgurram@MC02Z52VDLVDQ ~ % python --version
Python 2.7.18
can u help me

Collapse
amazinggrace2019 profile image
Unicorn

Hi,
I am still stuck
(base) Carolines-MBP:~ carolinekibat$ ls -1 /usr/local/bin/python*
/usr/local/bin/python
/usr/local/bin/python3
/usr/local/bin/python3-config
/usr/local/bin/python3.8
/usr/local/bin/python3.8-config
(base) Carolines-MBP:~ carolinekibat$ ln -s -f /usr/local/bin/python3.8 /usr/local/bin/python
ln: /usr/local/bin/python: Permission denied

Then I tried pip
(base) Carolines-MBP:~ carolinekibat$ python --version
Python 2.7.14 :: Anaconda, Inc.
(base) Carolines-MBP:~ carolinekibat$ pip3 --version
pip 20.1.1 from /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8)
(base) Carolines-MBP:~ carolinekibat$ pip3 install --upgrade pip
Requirement already up-to-date: pip in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (20.1.1)
(base) Carolines-MBP:~ carolinekibat$ which pip
/Library/Frameworks/Python.framework/Versions/3.8/bin/pip
(base) Carolines-MBP:~ carolinekibat$ sudo ln -s -f /usr/local/bin/python3.8 /usr/local/bin/python
Password:

close and open terminal

Last login: Sat Jun 27 20:32:57 on ttys000
You have new mail.
(base) Carolines-MBP:~ carolinekibat$ python --version
Python 2.7.14 :: Anaconda, Inc.
(base) Carolines-MBP:~ carolinekibat$

Why doesn't it change to python 3?

Collapse
rayahm24 profile image
rayahm24

Hey Irfan, Installed homebrew and did all the steps but it still says that the version is 2.7. 16
This is basically the code I got.

Rayyans-Air:~ rayyanahmed$ python --version
Python 2.7.16
Rayyans-Air:~ rayyanahmed$ brew link python@3.8
Linking /usr/local/Cellar/python@3.8/3.8.4...
Error: Could not symlink bin/2to3
Target /usr/local/bin/2to3
already exists. You may want to remove it:
rm '/usr/local/bin/2to3'

To force the link and overwrite all conflicting files:
brew link --overwrite python@3.8

To list all files that would be deleted:
brew link --overwrite --dry-run python@3.8
Rayyans-Air:~ rayyanahmed$ ls -l /usr/local/bin/python*
lrwxr-xr-x 1 rayyanahmed admin 26 Jul 21 11:36 /usr/local/bin/python -> /usr/local/bin/python3.8.3
lrwxr-xr-x 1 root wheel 69 Jul 19 17:42 /usr/local/bin/python3 -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/python3
lrwxr-xr-x 1 root wheel 76 Jul 19 17:42 /usr/local/bin/python3-config -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/python3-config
lrwxr-xr-x 1 root wheel 71 Jul 19 17:42 /usr/local/bin/python3.8 -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8
lrwxr-xr-x 1 root wheel 78 Jul 19 17:42 /usr/local/bin/python3.8-config -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8-config
Rayyans-Air:~ rayyanahmed$ ln -s -f /usr/local/bin/python3.8.3
Rayyans-Air:~ rayyanahmed$ ln -s -f /usr/local/bin/python3.8.3
Rayyans-Air:~ rayyanahmed$ python --version
Python 2.7.16

Collapse
steven410 profile image
Steven • Edited

I tried this and now get this when I run python --version:

Usage: /usr/local/bin/python [--prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--help|--abiflags|--configdir|--embed]

Anyone know what's going on?

EDIT: I fixed this. This step: "Change the default python symlink to the version you want to use from above." should be better explained as to what the command should be. I had changed the wrong part of it

Collapse
malwarebo profile image
Irfan Author

Thank you Steven! I have modified the post. Let me know if anything else needs to be changed.

Collapse
samerrustom profile image
samerrustom

Home-Macbook-Pro:~ pcmac$ ls -l /usr/local/bin/python*
lrwxr-xr-x 1 pcmac admin 24 Aug 16 17:03 /usr/local/bin/python -> /usr/local/bin/python3.7
lrwxr-xr-x 1 pcmac admin 38 Aug 16 17:13 /usr/local/bin/python3 -> ../Cellar/python@3.8/3.8.5/bin/python3
lrwxr-xr-x 1 pcmac admin 45 Aug 16 17:13 /usr/local/bin/python3-config -> ../Cellar/python@3.8/3.8.5/bin/python3-config
lrwxr-xr-x 1 pcmac admin 40 Aug 16 17:13 /usr/local/bin/python3.8 -> ../Cellar/python@3.8/3.8.5/bin/python3.8
lrwxr-xr-x 1 pcmac admin 47 Aug 16 17:13 /usr/local/bin/python3.8-config -> ../Cellar/python@3.8/3.8.5/bin/python3.8-config
Home-Macbook-Pro:~ pcmac$ ls -l /usr/local/bin/python*
lrwxr-xr-x 1 pcmac admin 24 Aug 16 17:03 /usr/local/bin/python -> /usr/local/bin/python3.7
lrwxr-xr-x 1 pcmac admin 38 Aug 16 17:13 /usr/local/bin/python3 -> ../Cellar/python@3.8/3.8.5/bin/python3
lrwxr-xr-x 1 pcmac admin 45 Aug 16 17:13 /usr/local/bin/python3-config -> ../Cellar/python@3.8/3.8.5/bin/python3-config
lrwxr-xr-x 1 pcmac admin 40 Aug 16 17:13 /usr/local/bin/python3.8 -> ../Cellar/python@3.8/3.8.5/bin/python3.8
lrwxr-xr-x 1 pcmac admin 47 Aug 16 17:13 /usr/local/bin/python3.8-config -> ../Cellar/python@3.8/3.8.5/bin/python3.8-config
Home-Macbook-Pro:~ pcmac$ ln -s -f /usr/local/bin/python3.8 /usr/local/bin/python
Home-Macbook-Pro:~ pcmac$ python --version
Python 2.7.16

Idle is still showing the old version:
Python 2.7.16 Shell

Collapse
samerrustom profile image
samerrustom

i have followed the mentioned steps to upgrade the installed Python version on my laptop, but when i run python --version the old version comes up.
I want to use the latest version 3.8 to use it on IDLE.

Collapse
fishbacp profile image
fishbacp • Edited

I found your tip extremely useful to solve the following problem I posted on stackoverflow:

I had a simple .py script that used tkinter, which I wanted to use to create a Mac OS app. I did my work using python 3.7 and IDLE. The script worked fine when run in IDLE, but the app I created using py2app and clear documentation at (py2app.readthedocs.io/en/latest/tu...) would not function,

I updated my Mac's python version from 2.7.16 to 3.7 and the app worked like a charm! Thanks--this made my day.

Collapse
osasuwayne profile image
suwayne

Thank you Irfan!!!

Collapse
kaxi1993 profile image
Lasha Kakhidze

Thanks Irfan

Collapse
dineshndev profile image
Dinesh Nagarajan

Thanks for the details. Unfortunately, it didn't work for me here is the solution worked for me

OS: Mac OS 10.15.3

Commands worked for me
unlink /usr/local/bin/python
ln -s /usr/local/bin/python3.7 /usr/local/bin/python

Collapse
tedster827 profile image
Teddy Williams

Thank you! I've being looking for a straight forward article to fix symlinks with Apple's lovely handy work.

Collapse
crimsonkida profile image
CrimsonKidA

Had to also run this:

export PATH=/usr/local/opt/python3/libexec/bin:$PATH

Thanks, all

Collapse
hanasaurusrex profile image
Hannah Busekrus

I changed the 3.7 in —— ln -s -f /usr/local/bin/python3.7 /usr/local/bin/python —— to match the version I installed, 3.9. Worked perfectly! Thank you!!

Collapse
malwarebo profile image
Irfan Author

Glad it helped you Hannah!

Collapse
parkco34 profile image
Cory Parker

This is not working for me either. I'm getting the same result for the python --version: Python2.7.16. I'm out of ideas on how to fix this.

Collapse
malwarebo profile image
Irfan Author

Why python-3.* version is installed on your system?

Collapse
heavenlyorange9 profile image
JUhn

Thanks. It's working~^^

Collapse
tamerhad profile image
tamerhad

Worked perfectly for Big Sur :) Thnx (y)

Collapse
waaaaaaaake profile image
Waaaaaaaake

Thank you, mister. Good job)

Collapse
roykamsi profile image
roykamsi

It worked also for me!! I've tried opensource.com but their tutorial wasn't working for me, I don't know why 🤷🏻‍♂️

Collapse
maeve70 profile image
LJ

Thank you!!!

Collapse
shaunmac profile image
Shaun MacDougall

Thank you, this worked a treat!

Collapse
trinadhkoya9 profile image
Trinadh Koya

This is awesome, ideally aliasing should also work

alias python='python3'

Collapse
hp_05032016 profile image
Hirpha

Ohh my God, I struggled for over 2hours! Thank you!

Collapse
victoryamaykin profile image
Victor Yamaykin

Worked in Visual Studio integrated terminal as well --- thank you!!!