How to set Python's default version to 3.x on OS X? [duplicate]
Changing the default python executable's version system-wide could break some applications that depend on python2.
However, you can alias the commands in most shells, Since the default shells in macOS (bash in 10.14 and below; zsh in 10.15) share a similar syntax. You could put
alias python='python3'in your
~/.profile, and then source
~/.profile in your
~/.bash_profile and/or your
~/.zsh_profile with a line like:
[ -e ~/.profile ] && . ~/.profile
This way, your alias will work across shells.
python command now invokes
python3. If you want to invoke the "original" python (that refers to python2) on occasion, you can use
command python, which will leaving the alias untouched, and works in all shells.
If you launch interpreters more often (I do), you can always create more aliases to add as well, i.e.:
alias 2='python2'alias 3='python3'
Tip: For scripts, instead of using a shebang like:
This way, the system will use python3 for running python executables.
Open ~/.bash_profile file.
Then put the alias as follows:
Now save the file and then run the ~/.bash_profile file.
Congratulation !!! Now, you can use python3 by typing python.