Had the same problem and the easy fix is to add:

    "python.analysis.stubPath": "",
    "python.analysis.indexing": true,

in your settings.json either in workspace or in user settings of VS Code. More about VS Code settings here: https://code.visualstudio.com/docs/getstarted/settings

Answer from chik182 on Stack Overflow
🌐
GitHub
github.com › microsoft › pylance-release › blob › main › docs › settings › python_analysis_autoImportCompletions.md
pylance-release/docs/settings/python_analysis_autoImportCompletions.md at main · microsoft/pylance-release
Auto-import completions are code completion suggestions provided by Pylance to automatically insert import statements for symbols (such as classes, functions, and constants) that are not currently imported into your code file.
Author   microsoft
Discussions

Pylance can not auto import python modules
Environment data Language Server version: v2022.6.30 OS and version: Windows 10 Pro Python version: Python 3.10.4 I created a small library (my_library) with an empty init.py file in the main modul... More on github.com
🌐 github.com
16
July 2, 2022
Auto-import doesn't work
Environment data Language Server version: 2020.6.1 OS and version: macOS Mojave 10.14.6 Python version: 3.8.2, installed via pyenv. Expected behaviour As demonstrated in the in Pylance announcement, I want to be able to automatically imp... More on github.com
🌐 github.com
41
July 2, 2020
Why is the Python Auto Import feature still such garbage compared to PyCharm
Yes, the Python extension (or really, Pylance) is pretty bad at suggestions and imports compared to other language extensions in VS Code like the ones for JS/TS, Java etc. Unfortunately Pylance is also closed source, so all you can do is open issues in microsoft/pylance-release and hope they get fixed at some point (not saing it's worse than PyCharm in this regard, but Pylance certainly has some catch-up work to do in terms of features). There is an experimental indexer you can enable by setting "python.analysis.indexing": true in your settings.json (note: the setting is so experimental that VS Code will tell you it's invalid). This will allow you to apply quick fix suggestions for adding missing imports from other files, but they still won't show when you try to autocomplete for symbols in other files. There is an issue tracking it: microsoft/pylance-release#1055 . So if you want better import completions, I'm afraid there's no alternative to PyCharm, for the moment. Personally I don't use Python for anything larger than a few small scripts here and there, so it hasn't bothered me that much. More on reddit.com
🌐 r/vscode
3
7
October 19, 2021
Auto import for VSCode
I'm not sure what you mean, but I think you need to install Django Rest Framework in your python environment. Once you do that, Pylance should pick up on that, if you have the correct Python Interpreter selected in VSCode. Does that help with your problem? More on reddit.com
🌐 r/django
8
6
October 17, 2022
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Pylance - Visual Studio Marketplace
2 days ago - Extension for Visual Studio Code - A performant, feature-rich language server for Python in VS Code
🌐
GitHub
github.com › microsoft › pylance-release › issues › 2991
Pylance can not auto import python modules · Issue #2991 · microsoft/pylance-release
July 2, 2022 - we are using VS Code as an IDE with Pylance extension · all dependencies (including my library) are installed there via python virtual environment ... I have a MyClass type definition in my library that is located in my_library/my_module_folder/my_class.py · I put MyClass somewhere in my project code, and click ctrl+. VS Code suggests adding auto-import: from my_library/my_module_folder/my_class.py import MyClass
Author   rustam-ashurov-mcx
🌐
Visual Studio Code
code.visualstudio.com › docs › python › editing
Editing Python in Visual Studio Code
November 3, 2021 - Pylance offers auto import suggestions for modules in your workspace and for packages you installed in your environment. As you type in the editor, you might get completion suggestions.
🌐
Microsoft Developer Blogs
devblogs.microsoft.com › dev blogs › microsoft for python developers blog › python in visual studio code – november 2022 release
Python in Visual Studio Code - November 2022 Release - Microsoft for Python Developers Blog
November 3, 2022 - Since auto imports were first implemented in Pylance, we’ve been getting a lot of feedback about how confusing and, sometimes, annoying it could be to have an import automatically added to a file when, for example, suggestions are accepted by accident. Starting this release, packages will no longer be imported automatically by default when using Pylance.
🌐
GitHub
github.com › microsoft › pylance-release › issues › 28
Auto-import doesn't work · Issue #28 · microsoft/pylance-release
July 2, 2020 - As demonstrated in the in Pylance announcement, I want to be able to automatically import packages as I type.
Author   imankulov
🌐
Reddit
reddit.com › r/vscode › why is the python auto import feature still such garbage compared to pycharm
r/vscode on Reddit: Why is the Python Auto Import feature still such garbage compared to PyCharm
October 19, 2021 -

I've switched from PyCharm to VSCode a few months ago, mostly because VSCode is faster and I use it anyhow for JS development.

For me, one of the most important features of an IDE/Editor is quickly add imports, and I just don't understand how VSCode has such a great reputation but is so so bad at this for Python. I half suspect/hope that this due to some misconfiguration from me, so please help me out if this is working good for you!

Here are some examples that I keep running into:

#1: Import Typings

Let's say I'm defining a function:

def foo(bar: List[Dict[str, Any]]):
    pass

And I wanna import the type definitions. Every reasonable IDE would put the from typing import ... suggestion at the very top. VSCode gives me 20+ partially matched suggestions that are alphabetically sorted sorted and I have to find the correct one. In contrast: PyCharm puts it on the top and it takes me a few milliseconds to import it. VSCode on the other hand rips me out of my flow and I have to search for 10+ seconds.

#2: Import from Project Files

This just happened to me: I have a Python project and created a new file shared.py where I defined an object with a pretty unique name. If I go to another file and write it, VSCode is completely lost. It has no clue what that is and where it could import it from. In contrast: PyCharm mostly get's it right, but takes a second or two sometimes.

#3: Auto-Import messes up the Code

In the cases VSCode actually finds suggestions from my code, it often keeps messing it up by confusing files with variables.

Example:

I have a file myproject/settings.py that contains a Pydantic class called Settings(BaseSettings):... and a variable settings = Settings(). Now, I see that these three kinds of "settings" can be confusing: The file, the class and the variable. However, PyCharm has a smart enough heuristic to understand that most of the time, I want to import the variable settings and puts it as the first suggestion. VSCode, on the other hand, doesn't even get that: The only suggestions I get are the file import settings OR the class from settings import Settings. You have no idea how often I quickly picked the second one, only to realise that VSCode not only added the wrong import, but also changed my code from settings to Settings, messing up my code.

Question: What to do?

My goal isn't to bash VSCode, because I want to keep using it. I just notice more and more how it gets in the way and keeps disrupting my flow with bad suggestions and wrong imports. And I find it hard to believe I'm the only one who's suffering from this, so please share your experience! It would be a shame if I have to move back to PyCharm and say goodbye to countless GB of RAM...

Here is my general setup / things I tried:

  • Python interpreter is correctly configured and VSCode restarted after

  • Interpreter is coming from a Poetry virtual env

  • Extensions:

    • Python

    • Pylance

    • Visual Studio IntelliCode

  • Relevant Settings:

    "python.diagnostics.sourceMapsEnabled": true,
    "vsintellicode.features.python.deepLearning": "enabled",
    "python.analysis.indexing": true,  // Found that somewhere on SO
    "python.languageServer": "Pylance",
    "python.autoComplete.addBrackets": true,
    "python.analysis.completeFunctionParens": true

I would really love to hear what you folks have to say to that and how I can improve my python experience in VSCode!

Find elsewhere
🌐
Microsoft Developer Blogs
devblogs.microsoft.com › dev blogs › microsoft for python developers blog › the pylance language server has reached stable!
The Pylance language server has reached stable! - Microsoft for Python Developers Blog
May 13, 2021 - Auto-import completions also include a clear preview of the import statement that will be added to your file in the completion tooltip so you know exactly what symbol you are importing. If you have already imported other submodules or functions from that module, Pylance will amend the existing statement by adding the new symbol alphabetically, helping to keep your imports organized.
🌐
GitHub
github.com › microsoft › pylance-release › issues › 178
Auto Import only on key press · Issue #178 · microsoft/pylance-release
July 27, 2020 - I would like to have the ability to choose when the auto-import actually imports modules, functions, etc. Currently, when I press Tab or Enter on IntelliSense completion suggestion the auto-import always imports the suggestion even if it is not necessary. For example, when writing tests and using fixtures there is no need to import fixture from conftest.py or any other global module.
Author   spinelsun
🌐
GitHub
github.com › microsoft › pylance-release
GitHub - microsoft/pylance-release: Documentation and issues for Pylance · GitHub
April 11, 2026 - Pylance provides a set of code actions that are available through the lightbulb menu (or Ctrl+. / Cmd+.). The exact titles can vary depending on context (e.g. the unresolved symbol name), but the actions below are what Pylance can offer. ... Add import: ... (adds a missing import for an unresolved symbol) ... Change spelling to ... (may also add an import when the best match is an auto-import)
Starred by 2.1K users
Forked by 1.1K users
Languages   Python 77.5% | Jupyter Notebook 22.5%
🌐
GitHub
github.com › microsoft › pylance-release › issues › 547
Auto import wont show options that haven't already been imported in the past · Issue #547 · microsoft/pylance-release
November 1, 2020 - Language Server version: Pylance ... e.g. Anaconda): Python 3.9 · Auto import should offer objects and modules from the standard libraries, my own project and installed libraries....
Author   basro
🌐
GitHub
github.com › microsoft › pylance-release › issues › 3816
Pylance no longer suggests auto imports and fails to suggest some obvious completions · Issue #3816 · microsoft/pylance-release
January 10, 2023 - Pylance used to show a suggestion of import os and it will automatically import it since it knew makedirs is under os.
Author   thethiny
🌐
Youssefm
youssefm.com › posts › writing-python-in-vscode
Writing Python in VS Code just got a whole lot better
Developing Python applications in VS Code just got a lot better this week with the release of Pylance version 2022.12.21. It introduces a new option that lets you auto import user symbols, saving you time and reducing interruptions to your flow.
🌐
GitHub
github.com › microsoft › pylance-release › discussions › 2681
Only top level suggestions are offered for auto imports · microsoft/pylance-release · Discussion #2681
Pylance · I would expect vs code to suggest imports from venvs. If you want to install a package on the venv, for example discord.py, and then import, for example, commands.Bot from discord.ext, press Ctrl +. to commands. I would expect the import from discord.ext import commands to be suggested, but it is not. Any other import found is suggested, but not from packages in venv. This also doesn't work with auto-imports.
Author   microsoft