Fixing missing ‘python’ error in macOS

til
python
poetry
Published

August 12, 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!