https://github.com/Microsoft/vscode-python/issues/21
Identify undeclared variables, find what module might have them, offer to insert import statement.
Is there any hints when this feature will be merged ?
@lauevrar77 - if you install Zenhub extension to Chrome you will be able to see our scrum board and the prioritized backlog.
It seems legit, I must admit :). So no rough deadline at this time ?
Looking forward!
Any updates? I'm missing this feature from PyCharm. As I can see #242 is closed and merged.
hopefully it won't use importmagic xD
some of the frequent issues I face:
https://github.com/alecthomas/importmagic/issues/47
https://github.com/pilat/vscode-importmagic/issues/9#issuecomment-455748126
but even if it does maybe we could do PRs on import magic itself xD
I think the second one could be done by skipping importmagic's sorting and triggering vscode one
No, it won't be using importmagic. We need to finish https://github.com/Microsoft/python-language-server/issues/425 first since it addresses performance, memory consumption as well as understanting or typing.
Any updates? Why is it blocked?
It is no longer blocked, but it is not in scope at the moment. There are other issues to attend to as we rewrote LS almost from scratch. I can't name specific time frame yet sorry.
Hi @MikhailArkhipov
Sorry a little off-topic but the rewrite you reference, do you know what version number that is and if it's rolled out in vscode? I notice a large memory footprint and want to see if the new version has helped. It could also be that the projects are large.
Thanks for the work.
It is not pushed to stable quite yet, but will be soon. You can test it ahead of time by putting this in your configuration:
"python.analysis.downloadChannel": "beta"
@jakebailey
Where should I add this ? And how can I test auto import ?
You no longer need beta channel as new LS in in stable. However, there is no auto-import feature if that is you wanted to test. As mentioned above, the issue is no longer blocked but it is not schedule to be implemented just yet.
I've built an extension that does exactly what the OP described. Hopefully this helps! https://marketplace.visualstudio.com/items?itemName=edb.vandelay
Is this something that will be worked on soon? This would be an awesome feature, and make this language server even more compelling than it already is!
This is one of the features that keeps me from using vscode.
Any plan when this will be available?
edb.vandelay doesn't suit me ;)
Are there any useful alternatives that can be easily installed and used right now?
@jedie Have you tried this one? https://marketplace.visualstudio.com/items?itemName=brainfit.vscode-importmagic
Any updates? When's the ETA?
The current PR for this is https://github.com/microsoft/python-language-server/pull/1656, and is being worked on.
When is the approximate release of this feature ?
You can already try this if you're on our daily build, but we're working on fixing other bugs before we can release everything to stable.
too bad the language server itself still cannot offer as good experience as jedi
For anyone else who has googled trying to set this up, I wrote a very quick blog post for how I fixed it.
@AlexSwensen what's shortcut/keyword for auto imports?
Only the word quick fix?
@jakebailey when you say stable, are you referring to the stable release for the language server or for vs code? if for this repo, how do i use the nightly build of this LS with vs code?
for some reason, i cannot get vs code to do simple code analysis such as detecting an undeclared variable, let alone an unresolved import.
is that what this language server is implementing? static code analysis for python in vs code?
I mean of the language server. We haven't been versioning here on GitHub, but do so for VS Code consumption of builds released from master. This feature has been out for a few months, but we're currently at 0.5.10. You can find the version printed by the LS.
Yes, the LS provides static analysis. If you have a problem, please report it as a new issue.
I am on vscode insiders 1.42.0 and language server version is 0.5.10.0. I followed @AlexSwensen 's link above and disabled jedi. But I still don't get any way to auto import, or have it suggest imports. It is looking at my proper venv as well. I dont get a quick fix option, and right clicking on the missing import doesn't show an option to add the import. Am I missing something?

Given that:
vscode-python does not use python-language-server (unless specifically directed, which I'm guessing few users do)vscode-python,maybe the maintainers of vscode-python should reopen https://github.com/microsoft/vscode-python/issues/21?
(cc @luabud and @DonJayamanne)
PS: thanks for the great work y'all!
Python extension has no code analysis facilities to detect missing imports or perform import resolution. All this requires code analysis and this is why feature is here. So reopening extension issue won't help much.
You are probably not getting light bulb (code action) because code could not determine where Page might be coming from. So it is not that feature is not implemented, it most probably this particular case is not completely handled or there is not enough information available.
Missing imports feature indexes libraries trying to determine where particular symbol is coming from. Indexing is not analysis, it is basically just parsing. Analysis of the entire Python installed libraries would take forever. So there is always limit of what index might recover. For example, it would not recover symbols available in compiled C++ code.
Thus, @autoferrit and @julien-c, please open separate issues with your specific case.
This is really the only missing feature from VSCode Python. I love how it works with Typescript, if we can get this feature working properly, PyCharm will have a hard time staying alive I believe.
Is there any update on when this feature will be released. It will really make using VS Code for Python development great.
This issue is closed, the code action (light bulb / diagnostic quick fix) for adding imports was implemented in October and has been released for a few months now. If you have an issue with the existing feature or comments on new features, please create a new issue as previously noted.
For those who wonder how to trigger auto-importing as I did, here are the steps.
Python: Jedi Enabled in your settings.Quick fix... For the last step, if it shows No quick fixes available or Checking for quick fixes, you may need to wait for a while until the extension has finished code analysis. It is also possible to set a shortcut that triggers a quick fix.
Jedi is disabled by default, I don't think that's the problem for most people.
What I believe is the main source of the confusion is that you need to explicitly enable linting in order to get this working.

Even though it is written in the official docs page, it's not immediately obvious honestly.
Are you sure Jedi is disabled by default now? This was not the case even a couple of weeks ago.
This feature doesn't work. I'm using 1.47.0-insider and the only way I get missing imports intellisense is if I use the Importmagic extension.
This wasn't obvious to me up until recently, but the official Python extension works great in combination with Pyright: https://github.com/microsoft/pyright
Pyright provides a bunch of other useful features, like suggesting automatic imports.
It also handles better some edge cases like types for pathlib.Path and others.
It's not a replacement for the Python extension but works very well on top.
This wasn't obvious to me up until recently, but the official Python extension works great in combination with Pyright: https://github.com/microsoft/pyright
Pyright provides a bunch of other useful features, like suggesting automatic imports.
It also handles better some edge cases like types for
pathlib.Pathand others.It's not a replacement for the Python extension but works very well on top.
Thanks! I've been using VSCode for so long and haven't even heard of it. It works great!
It should definitely be a part of the Python extension. The functionality it provides is sorely missing when moving from more advanced IDEs like PyCharm.
For those of you interested in what Pyright provides in VS Code, I would recommend looking at what we just posted today, a new LS based on Pyright that integrates fully with the Python extension.
Thanks for your patience!
Exciting! Congrats to the team. Looking forward to trying this out.
Looking forward to poetry virtualenvs being auto detected (at some point) ;)
I am not sure why so many people are so happy about PyLance as they missed to read between the lines: PyLance is not open-source. I kinda find very hard not to think about the Embrace, extend, and extinguish approach.
Today we add closed-sourced components, tomorrow mandatory free SaaS services and the day after tomorrow we start charging users for using them.
@ssbarnea I totally agree. The reason I use pylance, is because I have fight all the time with the existing tools to get autocomplete to work reliably. sometimes, it only works with words in the file. other, it knows nothing, other times, imports seem to be nothing related to what I want. I have been through so many articles it was just exhausting.
I decided to keep pylance when I installed it, said to use it as the completion engine, and it just worked, and it worked really nice (granted still nowhere near what pycharm gives, but for being free, its great). I will keep trying the LS version now and then to see if I can get it working again, but until then, I just want things to work so I can write code. That being said, I do REALLY look forward to the LS being more robust.
@ssbarnea any alternative to recommend? (and thanks for the link!)
I'm very disappointed that Pylance is closed-source and that the Microsoft Python Language Server will be no longer be supported in the future but having now wasted hours on getting import quick fixes working, it looks I have no other choice than to resort to Pylance for the time being. Here are the settings that I put in my workspace's settings.json to enable it:
"python.linting.enabled": true,
"python.jediEnabled": false,
"python.linting.pylintEnabled": false,
"python.linting.mypyEnabled": false,
"python.languageServer": "Pylance",
(Make sure pylint is disabled or otherwise import quick fixes might not work, probably because pylint conflicts with Pylance. As for the mypy setting, I didn't actually try mypy but simply wanted to prevent conflicts with Pyright which comes integrated in Pylance.)
Most helpful comment
I am not sure why so many people are so happy about PyLance as they missed to read between the lines: PyLance is not open-source. I kinda find very hard not to think about the Embrace, extend, and extinguish approach.
Today we add closed-sourced components, tomorrow mandatory free SaaS services and the day after tomorrow we start charging users for using them.