37
votes

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.

6
Please clarify what you mean by auto import extension. As it stands, your question doesn't make sense. - ifconfig
@ifconfig I am not sure, what is not clear in this question. Have you ever worked on Eclipse or IntelliJ? - Soumitri Pattnaik
You mean autocomplete features for the python in the visual studio code? - babygame0ver
@babygame0ver no, I mean, if you type sys.argv then it should automatically import the sys module. - Soumitri Pattnaik
okay. I don't think so buddy. If it will be then it will be for the atom. well i am using atom. :-( - babygame0ver

6 Answers

12
votes

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.

15
votes

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
7
votes

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.

4
votes

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.

  1. Enable Microsoft Python Language Server by removing the check of Python: Jedi Enabled in your settings.
  2. Reload the VSCode window.
  3. 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 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.

1
votes
0
votes

You can find it in VSCode extension store. it's name is IMPORTMAGIC. It works fantastic. It will include all modules which you use in your script.

It has code action ctrl + . , which will also import library.