Using a venv with Neovim's Python LSP
Tyler Smith

Tyler Smith @tylerlwsmith

About: I'm a software developer who writes about Laravel, JavaScript, Rails, Linux, Docker, WordPress and the tech industry. Follow me on Twitter @tylerlwsmith

Location:
Sacramento, California
Joined:
Apr 17, 2018

Using a venv with Neovim's Python LSP

Publish Date: Apr 5 '24
12 1

I recently started coding with Neovim using kickstart.nvim as the template for my editor configuration. I downloaded the python-lsp-server package using Mason, but I was disappointed to discover that the IntelliSense on my third party dependencies didn't work. The LSP was resolving to my global Python installation, which did not have the packages from my virtual environment (venv) installed.

In VS Code, I can press cmd + shift + P and then type Python: Select Interpreter, which allows me to select the interpreter from my project's virtual environment. However, I did not see an equivalent feature available in my Neovim installation. A cursory Google search for "use venv on neovim" turned up dozens of results about Neovim plugins that can be used to manage virtual environments automatically. Because I was brand new to Neovim, I didn't yet feel comfortable installing and configuring plugins in Lua.

A simpler way

Buried in one of the search results where users offered suggestions for venv management plugins, a user named vihu offered a much simpler solution that did not require additional software or configuration.

Here is the gist of vihu's solution:

cd my_python_project
source .venv/bin/activate
nvim
Enter fullscreen mode Exit fullscreen mode

That's it.

By sourcing the venv before you start Neovim, the python-lsp-server automatically uses the venv Python interpreter and its dependencies. This provides IntelliSense for third party modules installed inside the virtual environment.

I hope this helps you as we suffer through Neovim together.

Comments 1 total

  • Rafael
    RafaelJul 11, 2025

    Although it's simple and it works if you have, for example, a dagger.io python module and some three or four python lambdas in the same repo and would like to keep only one neovim instance things starts to crack...

Add comment