This happens because Pylance—the default language server for VS Code—does not automatically know where Poetry is hiding your project's virtual environment.
Pylance resolves imports based on the active Python interpreter. By default, Poetry creates virtual environments in a centralized system cache, which Pylance often misses.
Here is the definitive guide to linking Poetry with Pylance and eliminating missing import errors permanently. Why Pylance Can't Find Your Poetry Imports pylance missing imports poetry link
This solution is elegant because it keeps all your project configuration in a single file. Pylance is built on Pyright, and many of its settings can be defined directly in pyproject.toml . This can solve a few issues at once:
Method 1: Tell VS Code to Use the Poetry Environment (Recommended) Here is the definitive guide to linking Poetry
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.
Open the Command Palette using Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (macOS). Type and select . This can solve a few issues at once:
Run this command in your terminal to force Poetry to build a .venv folder directly inside your current project root: poetry config virtualenvs.in-project true Use code with caution. Step 2: Rebuild the environment
When you install packages via pip globally or in a standard .venv folder inside your project directory, VS Code usually detects them automatically. However, Poetry’s default behavior is to isolate virtual environments inside a global, centralized system directory:
You will now see a .venv folder inside your project workspace. Restart VS Code, and Pylance will automatically detect the imports. Method 2: Manually Select the Poetry Interpreter in VS Code
Now go forth and code without the yellow squiggles.