Then force Pylance to reload: Developer: Reload Window in VS Code.
The most common fix is telling VS Code exactly which Python executable to use. VS Code often defaults to a global system Python rather than your Poetry environment. Stack Overflow Open the Command Palette Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P Search for Interpreter : Type "Python: Select Interpreter" and select it. Find your Poetry Env
[tool.pyright] include = [".venv"] exclude = [".git"] pylance missing imports poetry link
Alternatively, you can delete the .vscode folder in your project and restart VS Code to clear any cached configurations. Summary of Best Practices
Resolving PyLance missing imports in a Poetry-managed project involves ensuring that PyLance has access to the correct virtual environment and project dependencies. By following the steps outlined above and verifying your project's configuration, you should be able to resolve the issue and get back to productive coding. Then force Pylance to reload: Developer: Reload Window
Type Python: Select Interpreter .
要解决问题,首先需要理解它的本质。 By following the steps outlined above and verifying
: If the yellow squiggly lines persist, force Pylance to clear its cache. Open the Command Palette ( Ctrl/Cmd + Shift + P ) and run Python: Restart Language Server .
"python.analysis.extraPaths": [ "/path/to/poetry/venv/lib/python3.12/site-packages" ]
最直接且最可靠的方法是让 VS Code 使用 Poetry 的虚拟环境。