Enable Neovim's Built‑in LSP for Python with pyright
Learn how to activate Neovim’s built‑in LSP client for Python using pyright, with step‑by‑step installation, configuration, verification, and troubleshooting.
17 Jan 2026, 17:35 UTC

Desired outcome
After completing this guide, Neovim will use its built‑in LSP client to provide real‑time diagnostics, code completion, signature help, and go‑to‑definition for Python files via the pyright language server, giving an IDE‑like experience without installing extra plugins.
Prerequisites
- Neovim version 0.5 or newer (run
:versioninside Neovim to confirm). - A working Python 3 interpreter accessible from your shell.
- The pyright language server installed globally, e.g. via npm (
npm i -g pyright) or pip (pip install pyright). - Write access to your Neovim configuration directory (
~/.config/nvimon Linux/macOS,%LOCALAPPDATA%\nvimon Windows).
Procedure
Install pyright if it is not already available. Choose one of the following commands and run them in a terminal with sufficient permissions to install globally:
# Using npm (requires Node.js) npm i -g pyright # Or using pip pip install pyrightVerify that the
pyrightexecutable is in your$PATH:pyright --versionThis should print a version number without error.
Open (or create) your Neovim init file:
# Linux/macOS nvim ~/.config/nvim/init.lua # Windows nvim %LOCALAPPDATA%\nvim\init.luaAdd the following Lua snippet to the file. It defines a function that starts the pyright client and attaches it automatically when a Python buffer is opened.
vim.lsp.start({ name = "pyright", cmd = { "pyright", "--langserver" }, -- adjust if pyright is not in PATH root_dir = vim.fs.dirname(vim.fs.find({ "pyproject.toml", "setup.py", "requirements.txt", ".git" }, { upward = true })[0]) or vim.loop.cwd(), }) -- Attach to Python files automatically vim.api.nvim_create_autocmd("FileType", { pattern = "python", callback = function() vim.lsp.buf_attach_client(0, vim.lsp.get_active_clients({ name = "pyright" })[1].id) end, })Save the file and restart Neovim (or source the config with
:source $MYVIMRC).
Expected checks
Run
:LspInfoinside Neovim. You should see an entry namedpyrightunder "Attached clients".Open a Python file (e.g.,
test.py) and verify completion:- In insert mode, type a few letters of a known identifier (e.g.,
priforprint) and observe the popup menu. - Alternatively, press
Ctrl+X Ctrl+Oto trigger omnifunc completion.
- In insert mode, type a few letters of a known identifier (e.g.,
Check diagnostics: introduce a syntax error (e.g., delete the colon after a function definition) and confirm that a red underline or a sign appears in the sign column.
Test go‑to‑definition: place the cursor on a function or variable name and press
gd. The cursor should jump to the definition within the project.
Recovery options
- If
:LspInfodoes not show pyright, examine the LSP log with:LspLogfor error messages. - Ensure the
pyrightexecutable is reachable: runwhich pyright(Linux/macOS) orwhere pyright(Windows) from a shell and verify the path matches what Neovim sees (:echo $PATHinside Neovim). - Temporarily disable the autocommand by commenting out the
vim.api.nvim_create_autocmdblock, restart Neovim, and manually start the client with:lua vim.lsp.start({name='pyright', cmd={'pyright','--langserver'}})to isolate the issue. - Reinstall pyright (
npm i -g pyright@latestorpip install --upgrade pyright) and repeat the verification steps. - If you are using another LSP configuration method (e.g., nvim‑lspconfig), remove or comment out those settings to avoid duplicate clients.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.