Pynvim is the official Python client and plugin host for Neovim, enabling Python developers to interact with Neovim instances and write powerful remote plugins. Currently at version 0.6.0, it is actively maintained with regular releases addressing bug fixes, performance improvements, and new features.
pip install pynvimVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to connect to a running Neovim instance using a Unix domain socket and interact with it. It executes a command, reads from the current buffer, and sets a global Neovim variable. Ensure Neovim is started with `nvim --listen /tmp/nvim.sock` (or similar for Windows/TCP) for the client to connect.
Upgrade your Python environment to 3.7 or newer. For best results with `pynvim >=0.6.0`, use Python 3.9+.
Upgrade pynvim to version 0.6.0 or higher: `pip install --upgrade pynvim`. If still encountering issues, ensure your Python installation is compatible.
Update all import statements from `import neovim` to `import pynvim`. When upgrading, it's safest to `pip uninstall neovim` then `pip install pynvim`.
To update a Vimscript dictionary, you must re-assign the entire dictionary back to Neovim. For example: ```python my_dict = nvim.vars['my_dict'] my_dict['field1'] = 'new_value' nvim.vars['my_dict'] = my_dict # Re-assign the modified dictionary ```
Avoid making synchronous Neovim API calls from within `async` (default `sync=False`) plugin handlers. If a return value is required, the handler must be explicitly marked `sync=True`. For non-blocking operations within async handlers, use `async_=True` for Neovim requests or schedule new callbacks with `nvim.async_call`.
1. Ensure `pynvim` is installed for the Python interpreter Neovim uses (check `:py3 print(sys.executable)` and `:py3 import pynvim`). 2. If using a virtual environment, tell Neovim its path by setting `vim.g.python3_host_prog` in your Neovim config (e.g., `init.lua` or `init.vim`): `let g:python3_host_prog = '/path/to/your/venv/bin/python'` (Vimscript) `vim.g.python3_host_prog = '/path/to/your/venv/bin/python'` (Lua) 3. Run `:checkhealth` in Neovim to diagnose further.
This often indicates an issue within Neovim or a plugin. 0.6.0 improves handling, but the root cause might be external. Check Neovim's logs (if enabled, e.g., `NVIM_PYTHON_LOG_FILE=logfile nvim`), review your Neovim configuration and plugins for instability, and ensure the Neovim process remains active during `pynvim` interaction. If connecting via `socket`, verify the socket file `/tmp/nvim.sock` exists and Neovim is listening.
Instead of `asyncio.run()`, use `await` directly for awaitable objects if you are within an `async` function managed by the event loop. If you need to run a task concurrently without blocking, schedule it using `asyncio.create_task()` or `nvim.async_call()`.
No dependency data recorded yet.