DEV Community

Tyler Smith
Tyler Smith

Posted on

6

Using a venv with Neovim's Python LSP

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.

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more