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 OverflowHad 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
Pylance's "quick fix" and "auto import" functions are available. It displays the modules that have been used by default, especially the files in the current project have used this module.
It is recommended that you disable other unrelated extensions to avoid interference between extensions. In addition, please try to reinstall the extension "Pylance" and reload VSCode.

Reference: Auto-import doesn't work.
Pylance can not auto import python modules
Auto-import doesn't work
Why is the Python Auto Import feature still such garbage compared to PyCharm
Auto import for VSCode
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": trueI would really love to hear what you folks have to say to that and how I can improve my python experience in VSCode!
How to make possible auto imports from Django Rest Framework in VSCode.
I have Pylance extension but it doesn't work
This is tracked by an open enhancement request: Allow auto-import abbreviations to be configured #2589. I suggest that you give that discussion an upvote to show support for it. You can also subscribe to it to get notified about discussion and progress. Please avoid making noisy comments there like ones that just consist of "+1" / "bump".
These abbreviations seem to be hard-coded in Pylance. As of the latest version (v2024.8.1), the defined abbreviations are:
npfornumpypdforpandastffortensorflowpltforpyplot/matplotlibmplformatplotlibmformathspioforio/scipyspforscipypnforpanelhvforholoviews
I don't think you can add new ones from user-side. You can, however, make a request by creating an issue at @microsoft/pylance-release.







