Link: Pylance Missing Imports Poetry

"python.analysis.extraPaths": [ "/Users/yourusername/.cache/pypoetry/virtualenvs/your-project-py3.11/lib/python3.11/site-packages" ] Use code with caution.

"python.analysis.extraPaths": ["./src", "./myproject"]

当 Poetry 项目的结构比较复杂(如依赖本地开发的包、使用 monorepo 管理多个项目等),仅切换解释器可能还不足以让 Pylance 找到所有导入时,可以通过显式配置搜索路径来解决。

"python.analysis.extraPaths": [ "./src", "$workspaceFolder/libs/shared" ] pylance missing imports poetry link

: If the environment doesn't appear:

Pylance needs to know where to find the dependencies installed by Poetry. To do this, you can configure Pylance to use the Poetry virtual environment.

Pylance looks at your workspace folder, doesn't see a venv folder, and assumes you are working in a global environment—which has none of your Poetry packages. Hence: "python

Here is a solid, actionable guide to fixing missing imports when using Poetry in VS Code.

Press Ctrl+Shift+P (or Cmd+Shift+P on Mac) to open the . Type and select Python: Select Interpreter .

To make the "missing imports" problem never return, automate the interpreter selection using a VS Code task that runs poetry install and extracts the environment path. Pylance looks at your workspace folder, doesn't see

[tool.pyright] venvPath = "~/Library/Caches/pypoetry/virtualenvs" venv = "your-project-name-xxxxx-py3.9"

After applying a solution, verify success:

If you already initialized your Poetry project, the existing virtual environment is still in the global cache. You need to delete it and reinstall your dependencies: Find the path of the current environment: poetry env info