Pylance Missing Imports Poetry Link __exclusive__ Official

Pylance maintains an internal cache of your workspace's structure. Sometimes this cache becomes stale. To reset it completely:

Choose the interpreter path associated with your Poetry environment. If you don't see it, run poetry env info --path in your terminal to find the exact location, then select "Enter interpreter path..."

Here are some code snippets to illustrate the configuration: pylance missing imports poetry link

When you use Poetry, your dependencies are installed in a dedicated virtual environment, typically outside your project directory (e.g., in ~/.cache/pypoetry/virtualenvs ). By default, VS Code and Pylance might be looking at the global system Python installation rather than the specific Poetry environment.

Replace 3.x with your actual Python version. Pylance maintains an internal cache of your workspace's

切换后建议执行以下操作确保 Pylance 识别新环境:

The most common cause is that VS Code is not pointing to the Poetry virtual environment. Open your project in VS Code. If you don't see it, run poetry env

By following these steps and troubleshooting tips, you should be able to resolve missing imports with Pylance and Poetry.

To ensure VS Code always detects your Poetry environment automatically, configure Poetry to create virtual environments inside your project folder.

Newer versions of Pylance (as of 2025) may all folders matching the pattern **/.* , which includes your local .venv folder. This means Pylance will ignore your dependencies even if you've selected the correct interpreter. You can override this by creating a pyright configuration section in your pyproject.toml file, which explicitly tells Pylance what to include or exclude: