-
Notifications
You must be signed in to change notification settings - Fork 126
Description
I'd like Neovim to automatically detect pynvim
even when it has been installed in its own virtual environment. Finding the python interpreter executable associated with pynvim
can be problematic when supporting a shared Vim configuration for multiple users on multiple platforms, as user preferences and operating system variations lead to a variety of different locations for the virtual environment.
The standard method for finding executables that have been installed in arbitrary locations is the PATH
environment variable. When the executable name is unique, it may be anywhere on PATH
, and the executable's actual location need not be configured.
To make it possible to detect the pynvim
virtual environment's python interpreter, I've been using the below Python shim and exposing it on PATH
as the executable named pynvim-python-interpreter
:
import subprocess
import sys
def main() -> None:
subprocess.run([sys.executable] + sys.argv[1:])
pynvim-python-interpreter
chains to the Python interpreter associated with the virtual environment where it was installed. pynvim
is a dependency that is also installed in that environment. The only Neovim configuration needed is to set g:python3_host_prog
to pynvim-python-interpreter
.
See https://github.com/drmikehenry/pynvim-python-interpreter for details on the implementation (published on PyPI as well). This makes installation straightforward: uv tool install pynvim-python-interpreter
If a similar shim were shipped as part of pynvim
itself, then pynvim
could be installed using uv tool install pynvim
. I've saved the shorter name pynvim-python
as a suggestion for pynvim
to use in lieu of pynvim-python-interpreter
.
Neovim could automatically detect this interpreter and set g:python3_host_prog
via something like:
if !exists('g:python3_host_prog') && executable('pynvim-python')
let g:python3_host_prog = 'pynvim-python'
endif
With those changes, users could uv tool install pynvim
to place pynvim
in a dedicated virtual environment and require no additional Neovim configuration.