I decided to write down a bit of details about how I was able to install python requirements for neovim on Mac M3, because as it turns out, it is not as straightforward as doing it on Arch. But before we jump straight into action, a little bit background.
When you start nvim
and run :checkhealth
or specifically
:checkhealth provider
there are various diagnostic messages about the
requirements. We will focus on just the python related for this topic. When
there is no python installed on your system whatsoever, it can look like
the following:
Python 3 provider (optional) ~
- Using: g:python3_host_prog = "/opt/homebrew/bin/python3"
- WARNING No Python executable found that can `import neovim`. Using the first available executable for diagnostics.
- Executable: Not found
And here without pynvim
:
Python 3 provider (optional) ~
- Using: g:python3_host_prog = "/opt/homebrew/bin/python3"
- Executable: /opt/homebrew/bin/python3
- ERROR Command error (job=18, exit code 1): `'/opt/homebrew/bin/python3' -c 'import sys; sys.path = [p for p in sys.path if p != ""]; import neovim; print(neovim.__file__)'`
stderr: Traceback (most recent call last): File "<string>", line 1, in <module>ModuleNotFoundError: No module named 'neovim'
- Python version: 3.12.3
- pynvim version: unable to load neovim Python module
- ERROR pynvim is not installed.
Error: unable to load neovim Python module
- ADVICE:
- Run in shell: /opt/homebrew/bin/python3 -m pip install pynvim
On my system it currently as of v0.9.5 looks like the following:
Python 3 provider (optional) ~
- Using: g:python3_host_prog = "/opt/homebrew/bin/python3"
- Executable: /opt/homebrew/bin/python3
- Python version: 3.12.3
- pynvim version: 0.5.1dev0
- OK Latest pynvim is installed.
Everything is OK, both python3
and pynvim
are correctly recognized. You
might ask, why install python via brew, when mac comes with python3
preinstalled in /usr/bin/python3
. I was stumbled by this too, but one of
the reasons is when you want to install something else via brew
that has
a Homebrew python as a dependency, for instance magic-wormhole
(useful
for transferring files between two laptops quickly).
For a record, here is the list of what I tried, but failed in one way or another:
/opt/homebrew/bin/python3 -m pip install pynvim
brew install pynvim
pipx install pynvim
pipx install python-neovim
pipx install python-pynvim
pip3 install 'pynvim @ git+https://github.com/neovim/pynvim'
And here is at least a part of the steps that worked for me. Start by installing python via Homebrew:
brew install python
Point neovim to our Homebrew python location:
let g:python3_host_prog = '/opt/homebrew/bin/python3'
Install pynvim
:
pip3 install 'pynvim @ git+https://github.com/neovim/pynvim' --break-system-packages
The parameter --break-system-packages
naturally implies that we are doing
something which should not be done by default, so I do not encourage you
use this solution. But maybe if you are desperate, as I was, you could do
your research and weight the risks involved in such operation and go for
it.
Down below, there is a Github link to a massive thread discussing the problems with python and Homebrew which in my opinion is an excellent starting point for learning, so if you have time, do not forget to take a look. Even though it is extremely long, the link points straight to the most important comment, to save some time. Enjoy!