Missing Imports Poetry Link: Pylance

Poetry sometimes uses symlinks. Force VS Code to follow them:

// .vscode/settings.json
"python.analysis.followSymlinks": true,
    "python.analysis.extraPaths": [
        "./.venv/lib/python3.x/site-packages"
    ]

You have a Poetry-managed project. Your code runs perfectly with poetry run python script.py, but Pylance (VS Code’s Python language server) underlines imports in red, saying “import could not be resolved”.

Make sure VS Code’s terminal uses the Poetry environment automatically:

poetry shell
code .

Or set the default shell for VS Code’s integrated terminal to run poetry shell on start. pylance missing imports poetry link


Pylance doesn’t automatically know about Poetry’s virtual environment. It defaults to the system or a previously selected Python interpreter, which lacks your project’s dependencies.

After applying a solution, verify success:


Run poetry env info --path and paste the result directly into the config: Poetry sometimes uses symlinks


    "python.defaultInterpreterPath": "/home/user/.cache/pypoetry/virtualenvs/my-project-abc123-py3.9/bin/python"

Warning: If you delete and recreate the Poetry environment (e.g., after updating dependencies), the hash abc123 changes, and this breaks. Use this only for personal, stable projects.

After any fix, restart Pylance:
Ctrl+Shift+PPython: Restart Language Server.


Rating this solution: ⭐⭐⭐⭐⭐
Fixes 95% of “Pylance + Poetry import missing” issues without hacks. You have a Poetry-managed project

This is a common frustration for Python developers using Visual Studio Code. The issue usually stems from Pylance (VS Code's language server) not knowing where Poetry has installed your virtual environment, or not selecting the correct interpreter.

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


Related Articles

Back to top button