DEV Community

Jordi Cuevas
Jordi Cuevas

Posted on • Updated on

How to install python2 in a macbook M1 with brew

Today, I need it to clone a repository of a project I'm working on, and after I run

npm install
Enter fullscreen mode Exit fullscreen mode

it returns python2 executable not found. so here are the steps to install python in your macbook.


  1. First of all , you should have installed brew.
  2. After you install brew run the following command
brew install pyenv
Enter fullscreen mode Exit fullscreen mode

pyenv (python version management) will help us on having multiple python versions in our pc.

  1. After the installation of pyenv we can now proceed to install the required python version we need with the following command:
pyenv install 2.7.18

Enter fullscreen mode Exit fullscreen mode
  1. once the installation completes we can export our env variables like this
export PATH="$(pyenv root)/shims:${PATH}"

Enter fullscreen mode Exit fullscreen mode
echo 'PATH=$(pyenv root)/shims:$PATH' >> ~/.zshrc

Enter fullscreen mode Exit fullscreen mode

After restarting my shell and try to install the dependencies of the project I found one more time there is not a python2 executable , but you are wondering what I did wrong? if I just installed it. Well we need to tell pyenv to use the version of python running the following command in our terminal

pyenv init

Enter fullscreen mode Exit fullscreen mode

Make sure to follow the instructions for configuration, and after restarting your terminal we can tell our shell to use the python version we need

pyenv shell 2.7.18

Enter fullscreen mode Exit fullscreen mode

and that's it , we have now python2 configure in our macbook.

Top comments (6)

andrewbaisden profile image
Andrew Baisden

Nice simple guide 👍

johnedee profile image

If you just need the latest version of Python2 on a modern Mac, you can download an installer from, v2.7.18 is here. That installer worked fine in Ventura for me, whereas the method detailed here kept crashing in the "pyenv shell" command. I'm sure there's some way to fix that, but if you just need python2 quickly, the installer from will get it done immediately.

beecher profile image

Thanks for the guide! I haven't been able to get it to work in Ventura — install seems to succeed, but then python --version just hangs, with no output.

silverium profile image
Soldeplata Saketos • Edited

It did not work in my mac with M2 Max chip. It finds python3, but not python2

mitalineer profile image

after running "pyenv init" I am restarting my iterm window. when I enter 'pyenv shell 2.7.18' , I am getting an error """pyenv: shell integration not enabled. Run `pyenv init' for instructions.""".

shlomiassaf profile image
Shlomi Assaf

Simple, helpful, easy.