Search code examples
pythonpython-venvpython-poetrypyright

Pyright can't see Poetry dependencies


In a poetry project the local dependencies are installed in the ~/.cache/pypoetry/virtualenvs/ folder. Pyright in nvim is complaining that import package lines can't be resolved. What should I include into pyproject.toml? Or how to show pyright the path to the dependencies? Thanks

My pyrightconfig.json looks like this:

{
    "venvPath": ". /home/ajanb/.cache/pypoetry/virtualenvs/",
    "venv": "tools-configfactory-materialmodel-jnEEQvIP-py3.10"
}

I found that I need to add this to the config file of neovim, can you help me to write it in .lua?

  au FileType python let b:coc_root_patterns = ['.git', '.env', 'venv', '.venv', 'setup.cfg', 'setup.py', 'pyrightconfig.json']

Solution

  • I spent days troubleshooting this. In the end, the only thing that worked was including this in my pyproject.toml:

    [tool.pyright]
    venvPath = "/Users/user/Library/Caches/pypoetry/virtualenvs"
    venv = "bfrl-93mGb6aN-py3.11"
    
    

    I'm also using this nvim plugin: poet-v

    I guess you could accomplish this through a proper LSP configuration, but I was just not familiar enough with lua and the lsp configuration to tackle that automatically.