There are many ways in which you can install Python on a Mac, directly from Python.org using dmg files or using the brew package manager.
Most macOS comes bundled with the latest version of Python 3.x as well as Python 2.7 and you may have installed others for your projects.
If you are wondering how to easily access these different versions using a Mac terminal, then the best way is to create an alias for them.
Based on which Terminal Shell you use, open the profile file ~/.bashrc or ~/.zshrc and add the aliases for different Python versions you have.
Example:# Alias for Python 2.7
alias python2='/usr/bin/python2.7'
# Alias for Python 3.8
alias python3.11='/Library/Frameworks/Python.framework/Versions/3.8/bin/python3'
# Alias for Python 3.9
alias python3.11='/Library/Frameworks/Python.framework/Versions/3.9/bin/python3'
# Alias for Python 3.11
alias python3.11='/Library/Frameworks/Python.framework/Versions/3.11/bin/python3'
Save and refresh the prompt and now you can easily access any Python version by simply using the. version number.

Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!