DEV Community

Jordi Cuevas
Jordi Cuevas

Posted on β€’ Edited on

24 1 1

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.

Steps

  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.

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (7)

Collapse
 
andrewbaisden profile image
Andrew Baisden β€’

Nice simple guide πŸ‘

Collapse
 
johnedee profile image
John β€’

If you just need the latest version of Python2 on a modern Mac, you can download an installer from Python.org, 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 Python.org will get it done immediately.

Collapse
 
mitalineer profile image
mitalineer β€’

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.""".

Collapse
 
vitorpbarbosa7 profile image
Vitor Pereira Barbosa β€’ β€’ Edited

this solved for me : eval "$(pyenv init -)"
credits:
github.com/pyenv/pyenv/issues/1959

Collapse
 
beecher profile image
Beecher β€’

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.

Collapse
 
silverium profile image
Soldeplata Saketos β€’ β€’ Edited

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

Collapse
 
shlomiassaf profile image
Shlomi Assaf β€’

Simple, helpful, easy.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

πŸ‘‹ Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay