Getting pyright to detect my poetry environment reddit / emacs ---------------------------------------------------------------------- desgreech · 2022-03-20 17:37 How do I get `pyright` to properly detect my `poetry` environment? I'm getting a lot of `Import "foo" could not be resolved` errors and missing completions because it's not seeing my poetry environment. I already have `poetry.el` (with `poetry-venv-toggle` toggled) and it's detecting my `poetry` project correctly, but `pyright` does not seem to be cooperating with it. Anyone experiencing the same issue? ---------------------------------------------------------------------- astoff1 · 2022-03-20 18:10 I suggest trying a generic environment management package such as envrc or buffer-env. ---------------------------------------------------------------------- a_atalla · 2022-03-20 19:06 By setting venvPath and venv config, https://github.com/microsoft/pyright/blob/main/docs/configuration.md ---------------------------------------------------------------------- ram535 · 2022-03-20 20:37 Could you provide an example? ---------------------------------------------------------------------- ram535 · 2022-03-20 20:43 I am having the same problem. I found this example project https://github.com/jaeheonji/python-boilerplate. Pyright has no problems finding the modules when I clone that repo. But when I create a project using the poetry command, pyright cannot find the modules. And I cannot figure it out why. ---------------------------------------------------------------------- 7890yuiop · 2022-03-21 01:17 I can't help, sorry. I'm just wondering why a thing to do with poetry was named `pyright` rather than `pywrite`. ---------------------------------------------------------------------- explore212 · 2022-03-21 02:12 I have installed poetry emacs package and set the poetry tracking mode to 1. Every time I edit some file in a python poetry project the venv gets activated. Also I have poetry config setup to put my venv locally in project inside .venv folder not sure if its got anything to do with your problem ---------------------------------------------------------------------- a_atalla · 2022-03-21 14:08 in `pyproject.toml` i do ``` [tool.pyright] venvPath="/home//.cache/pypoetry/virtualenvs" venv="" ``` if you are not using `pyproject.toml` you can create `pyrightconfig.json` in the project root ``` { "venvPath": "/home//.cache/pypoetry/virtualenvs", "venv": "" } ``` ---------------------------------------------------------------------- a_atalla · 2022-03-21 14:15 Maybe because it has `poetry.toml` that contains ``` [virtualenvs] in-project = true ``` this will create the venv in the project root, i tink that is why `pyright` could detect it ---------------------------------------------------------------------- by_wicker · 2022-03-21 15:55 It's not to do with poetry. Pyright is an LSP server for Python; poetry is a Python dependency and package management system. They don't have anything much in common except you want your Pyright to use the environment set up by Poetry. I assume they mean "right" as in "correct", though personally I actually might have chosen "wright" as in "shipwright" - meaning "builder", since an lsp server helps you build things. But I don't really know their rationale. ---------------------------------------------------------------------- 7890yuiop · 2022-03-21 20:33 Ah, so poetry is nothing to do with poetry, and pyright is nothing to do with poetry *or* poetry. The name makes more sense now. ---------------------------------------------------------------------- ram535 · 2022-03-22 01:34 This works for me. After creating a project: `poetry new example` Then run: `poetry install` And pyright has no problems finding the modules. ---------------------------------------------------------------------- desgreech · 2022-03-23 07:00 Thanks, this made it work for me!