DEV Community

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

Irfan on December 04, 2019

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 pytho...
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
 
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 •

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 •

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 •

Hey, what is your MacOS version?

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
 
davidfp profile image
David Fernández Puentes •

Good Job, It works for me. Thanks!

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 •

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 •

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 •

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
 
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 •

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

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 •

Did you try this:

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

Provided you have installed Python 3.9.

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
 
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
 
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
 
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
 
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
 
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
 
nick_sassow_afa10f1ecef7e profile image
Nick Sassow •

tried every command stream in the posts... No luck:

nick2@NWS-Pro-21 ~ % python3 --version
Python 3.8.9
nick2@NWS-Pro-21 ~ % python --version
Python 2.7.18
nick2@NWS-Pro-21 ~ % python -V
Python 2.7.18
python3 --version
Python 3.8.9

this is on macOS Monterrey 12.0.1

i am an oldie 62 ex unix 5.3.1 and a newbie at same time...

Collapse
 
zimanaanalytics profile image
Zimana Analytics #BlackInDataWeek • • Edited

This worked for me -- was able to connect to Python 3.9, so thank you for sharing this. I am not sure why Apple still ships with Python 2 (I have the M1 MacBook pro and still had this!) ;-)

Again, thank you!

Collapse
 
claracavalcante profile image
Ana Clara •

Thank you for the tutorial!

One thing I am not sure about is pip.

For some reason when I use "pip --version" the outcome is this:
pip 21.2.4 from /Library/Python/3.8/site-packages/pip (python 3.8)

and when I use "pip3 --version", the outcome is:
pip 21.2.4 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)

Any ideas on why are they using different python releases? And how to update it.

Collapse
 
claracavalcante profile image
Ana Clara •

I fixed this by reinstalling pip with the following the commands:

curl bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py

Collapse
 
osasuwayne profile image
suwayne •

Thank you Irfan!!!

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
 
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
 
kaxi1993 profile image
Lasha Kakhidze •

Thanks Irfan

Collapse
 
putroandrianto profile image
Andrianto Cahyono Putro •

worked! thanks

Collapse
 
rwheeler7864 profile image
Robert F Wheeler •

didn't work.
nice try though

ln -s -f /usr/local/bin/python3.9 /usr/local/bin/python
(venv) (base) robwheeler@Roberts-MBP practice-tools % python --version
Python 3.7.3
(venv) (base) robwheeler@Roberts-MBP practice-tools %

Collapse
 
leelou_ profile image
leelou _ •

I am frustrated... Nothing worked for me. Am i doing something wrong? (macOs 10.13.6)

Last login: Wed Jun 8 17:13:10 on ttys000
(base) Leelou:~ leelou$ ls -l /usr/local/bin/python*
lrwxr-xr-x 1 leelou admin 24 Jun 8 17:12 /usr/local/bin/python -> /usr/local/bin/python3.7
lrwxr-xr-x 1 root wheel 71 Oct 30 2019 /usr/local/bin/python-32 -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python-32
lrwxr-xr-x 1 root wheel 75 Oct 30 2019 /usr/local/bin/python-config -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python-config
lrwxr-xr-x 1 leelou admin 25 Jun 8 16:24 /usr/local/bin/python.old -> /usr/local/bin/python3.10
lrwxr-xr-x 1 root wheel 69 Oct 30 2019 /usr/local/bin/python2 -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python2
lrwxr-xr-x 1 root wheel 72 Oct 30 2019 /usr/local/bin/python2-32 -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python2-32
lrwxr-xr-x 1 root wheel 76 Oct 30 2019 /usr/local/bin/python2-config -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python2-config
lrwxr-xr-x 1 leelou admin 25 Jun 8 16:55 /usr/local/bin/python2.7 -> /usr/local/bin/python3.10
lrwxr-xr-x 1 root wheel 74 Oct 30 2019 /usr/local/bin/python2.7-32 -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-32
lrwxr-xr-x 1 root wheel 78 Oct 30 2019 /usr/local/bin/python2.7-config -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
lrwxr-xr-x 1 root wheel 70 Jun 8 16:42 /usr/local/bin/python3 -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/python3
lrwxr-xr-x 1 root wheel 72 Sep 26 2017 /usr/local/bin/python3-32 -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3-32
lrwxr-xr-x 1 root wheel 77 Jun 8 16:42 /usr/local/bin/python3-config -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/python3-config
lrwxr-xr-x 1 root wheel 78 Jun 8 16:42 /usr/local/bin/python3-intel64 -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/python3-intel64
lrwxr-xr-x 1 root wheel 73 Jun 8 16:42 /usr/local/bin/python3.10 -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10
lrwxr-xr-x 1 root wheel 80 Jun 8 16:42 /usr/local/bin/python3.10-config -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10-config
lrwxr-xr-x 1 root wheel 81 Jun 8 16:42 /usr/local/bin/python3.10-intel64 -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10-intel64
lrwxr-xr-x 1 root wheel 71 Sep 26 2017 /usr/local/bin/python3.6 -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
lrwxr-xr-x 1 root wheel 74 Sep 26 2017 /usr/local/bin/python3.6-32 -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6-32
lrwxr-xr-x 1 root wheel 78 Sep 26 2017 /usr/local/bin/python3.6-config -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6-config
lrwxr-xr-x 1 root wheel 72 Sep 26 2017 /usr/local/bin/python3.6m -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6m
lrwxr-xr-x 1 root wheel 79 Sep 26 2017 /usr/local/bin/python3.6m-config -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6m-config
lrwxr-xr-x 1 root wheel 78 Jun 19 2019 /usr/local/bin/python3.7-config -> ../../../Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7-config
lrwxr-xr-x 1 root wheel 72 Jun 19 2019 /usr/local/bin/python3.7m -> ../../../Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7m
lrwxr-xr-x 1 root wheel 79 Jun 19 2019 /usr/local/bin/python3.7m-config -> ../../../Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7m-config
lrwxr-xr-x 1 root wheel 69 Oct 30 2019 /usr/local/bin/pythonw -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw
lrwxr-xr-x 1 root wheel 72 Oct 30 2019 /usr/local/bin/pythonw-32 -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw-32
lrwxr-xr-x 1 root wheel 70 Oct 30 2019 /usr/local/bin/pythonw2 -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2
lrwxr-xr-x 1 root wheel 73 Oct 30 2019 /usr/local/bin/pythonw2-32 -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2-32
lrwxr-xr-x 1 root wheel 72 Oct 30 2019 /usr/local/bin/pythonw2.7 -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7
lrwxr-xr-x 1 root wheel 75 Oct 30 2019 /usr/local/bin/pythonw2.7-32 -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7-32

/usr/local/bin/python3.7:
total 0
drwxr-xr-x 13 leelou wheel 416 Jun 19 2019 site-packages
(base) Leelou:~ leelou$ pip3 --version
pip 22.1.2 from /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip (python 3.10)
(base) Leelou:~ leelou$ pip3 install --upgrade pip
Requirement already satisfied: pip in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (22.1.2)
(base) Leelou:~ leelou$ which pip
/Library/Frameworks/Python.framework/Versions/3.10/bin/pip
(base) Leelou:~ leelou$ sudo ln -s -f /usr/local/bin/python3.10 /usr/local/bin/python
Password:
(base) Leelou:~ leelou$ python --version
Python 2.7.17
(base) Leelou:~ leelou$

Collapse
 
victoryamaykin profile image
Victor Yamaykin •

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

Collapse
 
nick_sassow_afa10f1ecef7e profile image
Nick Sassow •

Tried
pip3 --version
pip 21.3.1 from /Users/nick/Library/Python/3.8/lib/python/site-packages/pip (python 3.8)
pip --version
zsh: command not found: pip

Collapse
 
davidofug profile image
David Wampamba •

Worked like charm on Macbook Pro 2017, 13" MacOS Catalina. Thank you

Collapse
 
thetif profile image
Tiffany •

Thank you so much. I assumed homebrew made that link for me. I guess either it did or it got overwritten. You've solved the problem that I've spent at least an hour on.

Collapse
 
driesvanspauwen profile image
driesvanspauwen •

I'm wondering why the command "which python" still returns usr/local/bin/python (which is in my case python 2), but "python -V" or "python --version" both return Python 3?

Collapse
 
hp_05032016 profile image
Hirpha • • Edited

I struggled for 2+hrs! Thank you!

Collapse
 
trinadhkoya9 profile image
Trinadh Koya •

This is awesome, ideally aliasing should also work

alias python='python3'

Collapse
 
shaunmac profile image
Shaun MacDougall •

Thank you, this worked a treat!

Collapse
 
maeve70 profile image
LJ •

Thank you!!!

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
 
waaaaaaaake profile image
Waaaaaaaake •

Thank you, mister. Good job)

Collapse
 
tamerhad profile image
tamerhad •

Worked perfectly for Big Sur :) Thnx (y)

Collapse
 
metacowboy profile image
Metaeditor •

How i could easily switch back to 2.7 if needet for one or other old project ?

Collapse
 
heavenlyorange9 profile image
JUhn •

Thanks. It's working~^^

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 •

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

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 •

Glad it helped you Hannah!

Collapse
 
crimsonkida profile image
CrimsonKidA •

Had to also run this:

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

Thanks, all

Collapse
 
salihz profile image
SaO •

this helped me and solved my problem. thank you!

Collapse
 
paulocezzar profile image
P S •

I have solved that by installing the script Update Shell Profile.command

in the python file found in Applications.

Collapse
 
dimazz profile image
dimazz •

// That worked for me on Big Sur

exec $SHELL -l
which python
/usr/local/bin/python
python --version

Collapse
 
clemoseitano profile image
Clement Osei Tano •

Awesome, thanks!

Collapse
 
tonsuchat profile image
Suchat Vattanasukkamon •

Thanks for the solution, So easily and clean!!

Collapse
 
1014violin profile image
Alexzzz •

Thank you so so so so so so much!!!!!! I've been trying to fix this for so long!!!!!

Collapse
 
malwarebo profile image
Irfan •

Glad it helped you Alex!

Collapse
 
__632db63a02 profile image
Павел Жиронкин •

Also, if after it python's version hadnt chaged just reload your device

Collapse
 
emilmartinov profile image
Emil Martinov •

How would you revert this?

Collapse
 
agusrdz profile image
Agustín Rodríguez •

Thanks, very simple and useful!

Collapse
 
malwarebo profile image
Irfan •

:)

Collapse
 
kryllyxofficial01 profile image
Kryllyx •

Thanks dude. It worked.

Collapse
 
malwarebo profile image
Irfan •

Glad it helped :)