When enabled, Pylance filters auto-import completion suggestions to show only packages declared as direct dependencies in your project's requirements.txt or pyproject.toml. This reduces noise from transitive dependencies and keeps completion lists focused on packages you actually use.
This setting affects auto-import completions only — the symbols that appear in the completion list with an import icon. The "Add import" code action (light bulb / Ctrl+.) continues to show all possible imports regardless of this setting.
| Value | Behavior |
|---|---|
false (default) |
Auto-import completions suggest symbols from all installed packages |
true |
Auto-import completions suggest symbols only from direct dependencies and user files |
Pylance reads the following files in your workspace root:
requirements.txt— including recursive-rincludespyproject.toml— both[project.dependencies]and[tool.poetry.dependencies]sections
Distribution names are automatically mapped to top-level module names (e.g., scikit-learn → sklearn, Pillow → PIL).
If neither file exists, the setting has no effect — all packages are shown as if the setting were false.
| Mode | Default value |
|---|---|
default |
false |
light |
false |
full |
true |
In full mode, this setting is enabled by default to improve the relevance of auto-import suggestions alongside the broader indexing depth.
{
"python.analysis.showOnlyDirectDependenciesInAutoImport": true
}With this enabled and a requirements.txt containing:
flask
requests
Auto-import completions will suggest symbols from flask, requests, the standard library, and your own workspace files — but not from transitive dependencies like werkzeug, urllib3, or certifi.
- Your project has many installed packages but you only import from a small set of direct dependencies.
- The completion list is cluttered with suggestions from packages you don't directly use.
- You are in
defaultorlightmode and want the focused suggestion behavior thatfullmode provides by default.
- Your project intentionally imports from transitive dependencies (e.g.,
werkzeugutilities in a Flask project). - You don't maintain a
requirements.txtorpyproject.tomland want all installed packages available.
python.analysis.autoImportCompletions— enable or disable auto-import completions entirelypython.analysis.packageIndexDepths— control how deeply packages are indexed for auto-importspython.analysis.languageServerMode— preset modes that adjust this and other settings
This document was generated with the assistance of AI and has been reviewed by humans for accuracy and completeness.