coc-pyright: can't seem to resolve reportMissingImports with coc-pyright on my python3.9 venv on neovim

Hi, I recently switched to neovim from vim yesterday and installed coc-pyright with it since coc-python’s README recommended it, I have a python3.9 venv at /opt/, I have extensively searched through issues here and found #87 similar to my issue. I have even installed pynvim in my venv with python -m pip install pynvim and added this line in my neovim init.vim:

let g:python3_host_prog = '/opt/bin/python'

Here is my output of CocInfo:

## versions
    
vim version: NVIM v0.4.3   
node version: v15.5.0
coc.nvim version: 0.0.80-cf0e8400a4
coc.nvim directory: /home/ubuntu/.config/nvim/plugged/coc.nvim
term: xterm-256color
platform: linux 
        
## Log of coc.nvim

2021-01-01T06:53:11.766 INFO (pid:4799) [services] - registered service "eslint"
2021-01-01T06:53:11.841 INFO (pid:4799) [services] - registered service "pyright"
2021-01-01T06:59:31.454 INFO (pid:4907) [services] - Pyright Server state change: stopped => starting
2021-01-01T06:53:11.926 INFO (pid:4799) [plugin] - coc.nvim 0.0.80-cf0e8400a4 initialized with node: v15.5.0 after 316ms
2021-01-01T06:53:11.945 INFO (pid:4799) [language-client-index] - pyright started with 4920
2021-01-01T06:53:12.251 INFO (pid:4799) [services] - Pyright language server state change: starting => running
2021-01-01T06:53:12.260 INFO (pid:4799) [services] - service pyright started
2021-01-01T06:53:15.585 INFO (pid:4799) [attach] - receive notification: showInfo []

I have added pyrightconfig.json on my venv root folder at /opt/:

{
    "include": [
        "**/site-packages",
        "**/cogs",
        "**/core"
    ],

    "exclude": [
        "**/__pycache__"
    ],

    "executionEnvironments": [
        {
            "root": "lib/python3.9/site-packages",
            "pythonVersion": "3.9",
            "pythonPlatform": "Linux"
        }
    ],

    "venvPath": "/opt",
    "reportMissingImports": true,
    "pythonVersion": "3.9",
    "pythonPlatform": "Linux"
}

and here is my coc-settings.json stored at ~/.config/nvim/:

{
    "python.pythonPath": "/usr/bin/python3.9",
    "python.venvPath": "/opt/"
}

even with these settings, whenever I open any *.py file, I get pyright showing warning about missing imports althought those packages are already present in my venv site-packages: /opt/lib/python3.9/site-packages

Is there anything I did wrong or I missed in these settings? I apologise for any inconvenience I’m still new with pyright, if someone can help me out I would be really grateful. 🙏🏼

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 3
  • Comments: 15 (6 by maintainers)

Most upvoted comments

@felippemr There is no setInterpreter command in coc-pyright.

It is recommended that you activate the virtual environment, then go to the project root and launch Vim/Neovim.

If you still cannot import correctly, place pyrightconfig.json in the project root and settting venvPath and venv appropriately.


Example: pyrightconfig.json

If the location of your virtual environment is /path/to/projectroot/.venv.

{
  "venvPath": "/path/to/projectroot"
  "venv": ".venv"
}

I am having the exact same issue on neovim. I added pyrightconfig.json at the project root but it won’t recognize any of my local imports.

Update: Just solved my issue. It seems the coc extension recognizes the root of your git repo as the root not the directory you open. I was using a subdirectory of a monorepo as my root and opening that with neovim on it’s own. I just moved the pyrightconfig.json to the correct root and added the prefix of my sub-directory to the root path in an execution environment and it worked.

I’m going to close this issue, open a new issue if you still has this error.

Are any of the people listed in this issue still having trouble with reportMissingImports?

The latest version of coc-pyright (v1.1.106) adds support for pyenv, pipenv, and poetry, which may further alleviate the import problem.

You all might want to give it a try.

@yaegassy, thanks. ~I tried that, but it didn’t work. Here is how I configured it.~ it worked!