I have a Python project in a subfolder within my git repo:


The virtual environment is installed in the api folder which is a subfolder of my git repo.

In an interpreter, I can import from myproj/foo.py by doing:

from myproj.foo import baz

But in Vim, coc-python reports:

unresolved import myproj.foo

and the autocompletion list includes the parent directory, api!


When I do :CocCommand > python.startREPL I can run the import just fine, without prepending api.

I can't even think about how to debug this problem!

Any pointers?


1 Answer 1


CoC assumes that a directory containing .git/ is the root of your project.

According to the CoC docs:

Unlike VSCode vim doesn't have workspace support. The solution is resolve workspace folders from opened files.

This means that CoC uses a list of filenames which, if present in a particular directory, indicate that it might be the project's root.

If the variable is not present, CoC falls back to a config setting called coc.preferences.rootPatterns which, by default is:

[".git", ".hg", ".projections.json"]

To override this behaviour you can set the list to include the name of your virtual environment. In this case:

autocmd FileType python let b:coc_root_patterns = ['.git', '.venv']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.