Is there a Python auto import extension/plugin available for Visual Studio Code?
By auto import I mean, auto import of python modules. Eclipse and Intellij has this feature with Java.
No, but it will soon be a part of vscode-python: https://github.com/Microsoft/vscode-python/pull/636
EDIT: See answer by @Eric, who built such an extension.
VSCode team recently released Pylance
Features
- Docstrings
- Signature help, with type information
- Parameter suggestions
- Code completion
- Auto-imports (as well as add and remove import code actions)
- As-you-type reporting of code errors and warnings (diagnostics)
- Code outline
- Code navigation
- Code lens (references/implementations)
- Type checking mode
- Native multi-root workspace support
- IntelliCode compatibility
- Jupyter Notebooks compatibility
I have built an automatic import extension that supports Python. It lets you fully customize how the imports get written to the file, modifying import paths, names, sorting relative to other imports. The Python plugin even lets you "group" imports together with extra line breaks.
From https://github.com/microsoft/python-language-server/issues/19#issuecomment-587303061:
For those who wonder how to trigger auto-importing as I did, here are the steps.
- Enable Microsoft Python Language Server by removing the check of
Python: Jedi Enabledin your settings.- Reload the VSCode window.
- Hover your mouse over the variable that you want to import, and click
Quick fix...For the last step, if it shows
No quick fixes availableorChecking 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.
I use this package it has over 31,000 downloads and works very well
https://marketplace.visualstudio.com/items?itemName=brainfit.vscode-importmagic
sys.argvthen it should automatically import the sys module. - Soumitri Pattnaik