: Open your terminal and run poetry env info --path . Copy this path.
In VS Code:
Choose and paste the copied path, appending /bin/python (Linux/macOS) or \Scripts\python.exe (Windows).
If Pylance points to a different Python environment than the one Poetry is using, it will not see the packages Poetry has installed. Hence, . pylance missing imports poetry link
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.
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.
Sometimes Pylance gets stuck.
"python.pythonPath": "$workspaceFolder/.venv/bin/python", "python.analysis.extraPaths": ["$workspaceFolder/.venv/lib/python3.x/site-packages"]
To ensure your environment is air-tight:
Even when a developer has tried to select the virtual environment, a common mistake is copying the root directory of the virtual environment (from poetry env info --path ) instead of the path to the actual python executable inside it. If VS Code doesn't find a valid interpreter, it will fall back silently to a default one without warning. : Open your terminal and run poetry env info --path
For Python developers using Visual Studio Code, the combination of (for dependency management and packaging) and Pylance (the official language server) is considered best-in-class. However, a frequent friction point arises: Pylance underlines perfectly valid imports from Poetry-installed packages with red squiggles, reporting Import "x" could not be resolved . The code runs fine, but the developer experience suffers—no autocomplete, no type checking, no go-to-definition.
To resolve "missing imports" in VS Code when using with Pylance , the issue typically stems from a mismatch between where Poetry installs packages and which interpreter Pylance is inspecting.
reportMissingImports when using Poetry is almost always a configuration issue where VS Code's language server is pointed at a different Python environment than the one where Poetry installed your packages. hrekov.com The Direct Solution: Selecting the Correct Interpreter If Pylance points to a different Python environment
最直接且最可靠的方法是让 VS Code 使用 Poetry 的虚拟环境。