Today, I need it to clone a repository of a project I'm working on, and after I run
npm install
it returns python2 executable not found. so here are the steps to install python in your macbook.
Steps
- First of all , you should have installed brew.
- After you install brew run the following command
brew install pyenv
pyenv (python version management) will help us on having multiple python versions in our pc.
- 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
- once the installation completes we can export our env variables like this
export PATH="$(pyenv root)/shims:${PATH}"
echo 'PATH=$(pyenv root)/shims:$PATH' >> ~/.zshrc
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
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
and that's it , we have now python2 configure in our macbook.
Top comments (7)
Nice simple guide π
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.
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.""".
this solved for me : eval "$(pyenv init -)"
credits:
github.com/pyenv/pyenv/issues/1959
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.It did not work in my mac with M2 Max chip. It finds python3, but not python2
Simple, helpful, easy.