A common and often hidden cause is Pylance's auto-exclusion rule. Recent versions auto-exclude any folder starting with a period ( . ), which includes Poetry's .venv directory. This causes Pylance to completely ignore the virtual environment and its installed packages.
VS Code, Pylance, and Poetry are a powerful combination for Python development. However, Pylance frequently triggers reportMissingImports errors even when your code runs perfectly. This happens because Pylance cannot find your virtual environment.
: A simple window reload ( Developer: Reload Window ) often resolves minor caching issues where Pylance misses newly installed packages. The Permanent Solution: In-Project Virtual Environments pylance missing imports poetry hot
Here’s a draft for addressing “Pylance missing imports when using Poetry” — structured for submission to the Pylance (or pyright) GitHub repository.
Fix: Pylance Missing Imports with Poetry in VS Code It is a common frustration: your code runs perfectly in the terminal via poetry run , but VS Code is a sea of yellow squiggly lines with Pylance shouting about "missing imports." This usually happens because Pylance is looking at your global Python installation instead of the virtual environment Poetry created for your project. A common and often hidden cause is Pylance's
This guide will walk you through every potential cause of the problem and its corresponding fix, from the most straightforward to the more specialized, helping you identify why Pylance can't "see" your Poetry dependencies and, more importantly, how to get those red squiggles to disappear.
: Run poetry run pip freeze to confirm the package is actually installed inside the environment. If it isn't, run poetry install again. This causes Pylance to completely ignore the virtual
"python.analysis.extraPaths": [ "~/.cache/pypoetry/virtualenvs/your-project-environment-name/lib/python3.11/site-packages" ] Use code with caution.
Run the Developer: Reload Window command from the Command Palette to force Pylance to re-scan the directories.