Xealot
Xealot

Reputation: 1659

PyCharm autoimport with autocomplete

I am giving PyCharm a try for the first time. Coming from an Eclipse/PyDev environment I have to say so far things have been going well.

There is one feature I am missing that I can't seem to find though and that is as follows:

In the auto-complete list in PyDev, when typing a symbol that doesn't exist in the file's scope it will show a list of modules that it's in. If you select that autocomplete item not only will PyDev complete the symbol for you but it will automatically add the import statement to take care of the dependency as well.

Does this exist in PyCharm?

So far it only seems to autocomplete things already in the scope of the document.

Upvotes: 15

Views: 8382

Answers (3)

east825
east825

Reputation: 909

These variants are already there, they are just not included in the basic completion and completion auto-popup for performance reasons. In order to see them you need to invoke completion for the second time at the same place or use a dedicated shortcut (search for "Second Basic Completion" in the keymap settings).

Auto-import extended completion demo

Upvotes: 0

Eugeniy Shablinskiy
Eugeniy Shablinskiy

Reputation: 41

I think this is definitely a bug or bad functional

Fresh installation of pycharm 2021.3.3, when writing code, the IDE itself automatically quietly puts some packages according to random words from the code. As a result, the environment was broken.

here is an example (that from pycharm eventlog):

source /home/user/.cache/pypoetry/virtualenvs/project-_uWvZL1R-py3.9/bin/activate
/home/user/anaconda3/bin/poetry add self

Using version ^2020.12.3 for self

Updating dependencies
Resolving dependencies...

Writing lock file

Package operations: 2 installs, 0 updates, 1 removal

  • Removing setuptools (62.6.0)
  • Installing decorator (5.1.1)
  • Installing self (2020.12.3)

  EnvCommandError

    × python setup.py egg_info did not run successfully.
    │ exit code: 1
    ╰─> [1 lines of output]
        ERROR: Can not execute `setup.py` since setuptools is not available in the build environment.
        [end of output]

Upvotes: 0

CrazyCoder
CrazyCoder

Reputation: 402335

See Settings | Editor | General | Auto Import.

Upvotes: 18

Related Questions