Developer Fix

Pylance Not Working in VS Code? Try These Fixes

If Pylance stops providing autocomplete, reports valid imports as missing, or remains stuck on loading, the cause is usually an extension conflict, wrong interpreter, corrupted workspace state, or an overloaded language server.

Difficulty: Easy–Medium Time: 15–30 minutes Updated: July 2026 Works for: Windows / macOS / Linux

Pylance powers much of the Python editing experience in VS Code: completions, type information, navigation, parameter hints, and import analysis. When it fails, your code may still run, but the editor starts acting like it has forgotten Python overnight.

Before changing settings, check whether the problem affects every project or only one workspace. A global problem usually points to the extension; a single-project problem usually points to the interpreter, environment, or workspace configuration.

Fix 1 — Confirm Python and Pylance are enabled

  1. Open Extensions with Ctrl + Shift + X.
  2. Find Python by Microsoft.
  3. Find Pylance by Microsoft.
  4. Make sure both are installed and enabled for the current workspace.
  5. Reload VS Code.

Workspace-specific disabling is easy to miss. An extension can be installed globally but disabled only in the folder you are working on.

Fix 2 — Select the interpreter used by the project

  1. Press Ctrl + Shift + P.
  2. Run Python: Select Interpreter.
  3. Choose the project’s virtual environment or intended Python installation.
  4. Open a new terminal.

Pylance analyses packages available to the selected interpreter. If it analyses Python 3.12 while your project packages live in a Python 3.11 environment, unresolved-import warnings are expected.

Fix 3 — Restart the language server

Open the Command Palette and run Python: Restart Language Server. If that command is unavailable, use Developer: Reload Window.

This clears many temporary failures after installing packages, switching branches, recreating a virtual environment, or changing interpreter paths.

Fix 4 — Check the Pylance output log

  1. Open View → Output.
  2. Use the dropdown in the Output panel.
  3. Select Python or Pylance.
  4. Look for repeated crashes, missing paths, or workspace indexing errors.

The log often reveals whether Pylance is reading the wrong environment or struggling with an enormous folder such as a dataset, generated build directory, or dependency cache.

Fix 5 — Exclude very large folders from analysis

Projects containing millions of generated files can slow Pylance or make indexing appear frozen. Exclude folders that do not contain source code. In workspace settings, use appropriate file exclusions for directories such as build output, node modules, large datasets, caches, or exported models.

Do not exclude your actual source directory. The goal is to reduce noise, not place the entire project under witness protection.

Fix 6 — Remove conflicting Python language extensions

Temporarily disable other extensions that provide Python completion, type checking, or language-server features. Run VS Code with only Microsoft Python and Pylance enabled, then test again.

If Pylance works, re-enable extensions one by one until the conflict returns.

Fix 7 — Correct unresolved import paths

If your project uses a non-standard source folder, open the actual project root in VS Code. You can also configure analysis paths for legitimate source directories, but avoid adding broad system folders simply to silence warnings.

Test the runtime first:

python -c "import your_module; print(your_module.__file__)"

If this command fails, the issue is not merely Pylance—the active Python environment cannot import the module either.

Fix 8 — Reinstall Pylance cleanly

  1. Uninstall Pylance.
  2. Reload VS Code.
  3. Install Pylance again from the official extension listing.
  4. Reload once more and select the interpreter.

Use this after the simpler checks. Reinstalling is useful for damaged extension files, but it cannot repair an incorrect project environment.

Fix 9 — Test with a clean profile or folder

Create a small folder with one file:

import os
print(os.getcwd())

Open that folder in VS Code and test completion after typing os.. If Pylance works there, the original workspace settings or project size is the likely cause.

FAQ

Why does Pylance show an import error when the code runs?

Pylance and the terminal may be using different interpreters or search paths. Align the selected interpreter and reload the language server.

Can I use Python without Pylance?

Yes. Your code can run without it, but you lose much of VS Code’s navigation, completion, and type-analysis experience.

Should I disable type checking to remove warnings?

Only after confirming the warning is not exposing a real environment or import issue. Disabling analysis can hide useful problems rather than solve them.