Last week I decided to finally upgrade my macOS BigSur to Sonoma. As usual I get issues after the upgrade. For example, security settings, apps permissions, custom backup script I put together to backup my files to a NAS drive stop working. This time I got error “Python3.9: bad interpreter: No such file or directory“.

I usually play around with Docker for personal projects and to improve my skills. I was working on a Python/Flask/SQLAlchemy app and decided to use my native python instead of creating another container in Docker. To solve the error above I did the following: (after brewing a great cup of coffee from Peru at home of course!)

  1. Installed Homebrew
  2. After installing Homebrew I ran: brew install pyenv

Next, you can use pyenv to manage your python versions – Very cool! Use the below command for example:

pyenv install 3.9.2 

If you desire a different version do:

pyenv install 4.x.x

Remember, you need to have macOS Xcode/Developer tools installed on your mac before having Homebrew.

Final steps – Update your bash_profile(I still use bash instead of zsh – yes!):

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile

If you do not have a /bin directory in your pyenv_root folder (you may only have a /shims directory) you may need to instead run this version of the command:

`echo 'export PATH="$PYENV_ROOT/shims:$PATH"' >> ~/.bash_profile`

Add pyenv to your Terminal:

echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bash_profile

And finally, reset your Terminal:

reset

I need to thank freeCodeCamp for the reference above. Again, you can contact me if you have any questions or if you like to collaborate. Also, check out my designs below

Leave a comment

Your email address will not be published. Required fields are marked *