Fixing Broken Imports with Neovim, Pylint, venv, and CoC


I strugged with this for a while, so I assume someone else will as well. As is often the case with configuration issues, the solution turned out to be straightforward.

Relevant parts of my dev environment

Problem statement

CoC/Pylint reports “E0401” import errors on libraries that are correctly installed in a virtual environment.

Pylint E0401

Cause

CoC is using the wrong Python interpreter to run pylint. In my case, it was running the system installation, when I needed it to run the interpreter for my virtual environment.

Fix

Point CoC to the right interpreter using :CocCommand python.setInterpreter and then selecting the one in my virtual environment.

Fixing pylint E0401

Hope this helps!