If you have a new Mac/Macbook with macOS Ventura 13.x or Sonoma 14.x, then you will notice that Python 2.7 or any 2.x version is not pre-installed on it. You will need to get it installed by yourself.
To do so, we can make use of the Homebrew package manager.
Step 1: Install pyenv using Homebrew
The first step you will do is install the Python version management tool.
brew install pyenv

Step 2: Install Python 2.x using pyenv
Once this is complete, we can install the Python 2.7.18 version using pyenv command.
pyenv install 2.7.18

Step 3: Add Python 2.7.x PATH to ZSH Profile
Finally, to python command work, you will need to add the PATH to the installed Python 2.7.x version to the .zshrc file.
export PATH=$PATH:/Users/code2care/.pyenv/versions/2.7.18
This is not an AI-generated article but is demonstrated by a human on an M1 Mac running macOS Sonoma 14.0.
Please support independent contributors like Code2care by donating a coffee.
Buy me a coffee!

Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!