Pylance: Missing Imports Poetry Link

If you don't see it, select and paste the path to your Poetry environment (find this by running poetry env info --path in your terminal).

Once selected, Pylance will re-index your project, and the missing imports errors should disappear. Automation and Best Practices

This command outputs the absolute file path to the virtual environment Poetry generated for this specific project. Copy this path to your clipboard. Step 2: Select the Interpreter in VS Code Open your project folder in VS Code.

VS Code and Pylance look for packages in the globally active Python environment or a local .venv folder within your workspace root. When Poetry saves packages in its global cache, Pylance loses the link between your project files and its external source code. To fix this, you must explicitly link Pylance to Poetry's virtual environment. pylance missing imports poetry link

Add the python.analysis.extraPaths property, pointing to the site-packages directory inside your Poetry cache. Your .vscode/settings.json file should look like this:

如果仅 Pylance 报红而代码实际能运行,说明解释器配置正确;如果代码也无法运行,则需要优先检查 Poetry 环境本身。

The fastest and cleanest way to resolve the missing import error is to select the Poetry virtual environment directly inside VS Code. Step 1: Get the path of your Poetry environment If you don't see it, select and paste

If you completed the steps above and still see missing import warnings, try these quick troubleshooting steps to force VS Code to update:

This happens because Poetry installs your project in ( -e ). Pylance needs help mapping your source code to the import path.

This acts as a manual override, forcing Pylance to look into that specific folder for autocomplete and type checking. Troubleshooting Persistent Issues Copy this path to your clipboard

poetry env info --path

To add dependencies to your project, use:

Once selected, Pylance will automatically scan the local .venv folder, and the missing import errors will disappear. Method 2: Point VS Code to Poetry’s Global Cache