Fixing missing ‘python’ error in macOS

til
python
poetry
Author
Affiliation
Published

August 12, 2024

Modified

December 16, 2024

After the last macOS update, I started getting the following error when trying to run poetry install:

[Errno 2] No such file or directory: 'python'

I went through GitHub issues, StackOverflow questions, and blog posts, but none of the suggested solutions worked.

Finally, I found the solution somewhat hidden in this blog post.

So, what’s the fix?

🥁 🥁 🥁

Just add the following line to your .zshrc file:

export PATH="$(brew --prefix python)/libexec/bin:$PATH"

This gets the installation prefix for python installed via Homebrew (e.g. /opt/homebrew/opt/[email protected]), gets the libexec/bin directory, and adds it to the PATH.

In that libexec/bin, there’s a python executable that gets called when you run python in the terminal.

That’s all. Hope that helps!

Citation

BibTeX citation:
@online{castillo2024,
  author = {Castillo, Dylan},
  title = {Fixing Missing “Python” Error in {macOS}},
  date = {2024-08-12},
  url = {https://dylancastillo.co/til/fixing-python-not-found-error-in-macos.html},
  langid = {en}
}
For attribution, please cite this work as:
Castillo, Dylan. 2024. “Fixing Missing ‘Python’ Error in macOS.” August 12, 2024. https://dylancastillo.co/til/fixing-python-not-found-error-in-macos.html.