How to set Python’s default version?

Changing the default python version system-wide would break some applications that depend on python2.

You can alias the commands in most shells, Mac OS X uses bash by default. If you also do, put this into your ~/.bash_profile:

alias python='python3'

python command now refers to python3. If you want the original python (that refers to python2), you can escape the alias i.e. doing \python will launch python2 leaving the alias untouched)

If you launch interpreters more often (I do), better is to:

alias 2='python2'
alias 3='python3'

Open a new shell session and these aliases will be available. If you want it to be effective in current session then you’ll have to source it:

source ~/.bash_profile

Tip for executable right way:

#!/usr/bin/env python


#!/usr/bin/env python3

the system will use python3 for running python executables.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.