Reputation: 61
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']
Upvotes: 4
Views: 6195
Reputation: 3069
I'm not using Neovim but I'm also using another terminal editor that uses LSP.
I solved the issue without any configuration.
Simply running poetry shell
before my editor solves the import issues.
For example:
poetry shell
<your editor command here>
Upvotes: 0
Reputation: 6822
If you are using Poetry, then the following shell snippet will create the file for you:
jq \
--null-input \
--arg venv "$(basename $(poetry env info -p))" \
--arg venvPath "$(dirname $(poetry env info -p))" \
'{ "venv": $venv, "venvPath": $venvPath }' \
> pyrightconfig.json
Upvotes: 8
Reputation: 101
This is how I solved this issue. Inside my pyproject.toml, I configured pyright like this (among other things):
[tool.pyright]
venvPath = "."
venv = ".venv"
Then I included a poetry.toml in my project with this:
[virtualenvs]
in-project = true
This way I don't have to discover the path and name of my virtual env, its always the same and available in-project.
Upvotes: 10
Reputation: 355
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.
Upvotes: 9