Pyright unable to import modules in my poetry environment

Hello,

I recently setup my nvim environment and I can’t seem to figure out why pyright does not seem to recognized my environment even though the lsp seems to be working fine. (go to definition works, I can even go to the definition of the import its saying its unable to import)

Here is my lspconfig

I’ve verify that in :checkhealth nvim seems to recognized my environment. (I don’t have neovim installed in my python environment, I don’t think that is needed?)

provider.python: require("provider.python.health").check()

Python 3 provider (optional) ~
- WARNING No Python executable found that can `import neovim`. Using the first available executable for diagnostics.
- WARNING Could not load Python :
  /Users/darren/Library/Caches/pypoetry/virtualenvs/simple-platformer-grm8zU49-py3.12/bin/python3 does not have the "neovim" module.
  /Users/darren/Library/Caches/pypoetry/virtualenvs/simple-platformer-grm8zU49-py3.12/bin/python3.12 does not have the "neovim" module.
  python3.11 not found in search path or not executable.
  python3.10 not found in search path or not executable.
  python3.9 not found in search path or not executable.
  python3.8 not found in search path or not executable.
  python3.7 not found in search path or not executable.
  /Users/darren/Library/Caches/pypoetry/virtualenvs/simple-platformer-grm8zU49-py3.12/bin/python does not have the "neovim" module.
  - ADVICE:
    - See :help |provider-python| for more information.
    - You may disable this provider (and warning) by adding `let g:loaded_python3_provider = 0` to your init.vim
- Executable: Not found

Python virtualenv ~
- $VIRTUAL_ENV is set to: /Users/darren/Library/Caches/pypoetry/virtualenvs/simple-platformer-grm8zU49-py3.12
- Python version: 3.12.6
- OK $VIRTUAL_ENV provides :!python.

LspInfo also looks ok to me

==============================================================================
lspconfig: require("lspconfig.health").check()

LSP configs active in this session (globally) ~
- Configured servers: bashls, pyright, cssls, html, ts_ls, lua_ls, clangd, robotframework_ls
- OK Deprecated servers: (none)

LSP configs active in this buffer (id=(invalid buffer)) ~
- Language client log: ~/.local/state/nvim/lsp.log
- Detected filetype: `(invalid buffer)`
- 0 client(s) attached to this buffer
- 1 active client(s) not attached to this buffer:
- Client: pyright (id: 1, bufnr: [6, 3])
  filetypes:       python
  root directory:  ~/code/simple_platformer
  cmd:             ~/.local/share/nvim/mason/bin/pyright-langserver --stdio
  autostart:       true

Docs for active configs: ~
- 

running :!which python also seems to recognized my env

:!which python
/Users/darren/Library/Caches/pypoetry/virtualenvs/simple-platformer-grm8zU49-py3.12/bin/python

I honestly don’t know what else to do. help

$ poetry shell
$ nvim --clean

?

buddy, i am in the same position: banging my head trying to understand what’s wrong. i would appreciate if you already figured it out. in the meanwhile, i can tell that coc-pyright just works (in both vim and neovim)! somehow it can automatically detect my virtual environment and all navigation also works.

the issue seems to be related to pylint.
see my answer here:

It’s a bit of a nasty oneliner but you can run

:lua vim.fn.setqflist({}, 'r', {title = 'Diagnostics', items = vim.tbl_map(function(diag) return {lnum = diag.lnum + 1, col = diag.col + 1, text = string.format("%s [%s]", diag.message, diag.source or "Unknown"), bufnr = diag.bufnr
} end, vim.diagnostic.get(nil))}); vim.cmd("copen")

to show the diagnostics in a quickfix list with the source of the diagnostic appended at the end. I’ve found this particularly useful with python projects since there is always a jumble of tools installed in the local venv and then globally.

I’ve been trying out GitHub - folke/trouble.nvim: 🚦 A pretty diagnostics, references, telescope results, quickfix and location list to help you solve all the trouble your code is causing. which helps.