PyCharm doesn't display suggestions for non-imported symbols while typing
In all JetBrains IDEs I've used (CLion, IDEA, WebStorm, DataGrip and GoLand) the IDE displays complete suggestions of symbols that are not currently imported in scope and accepting the suggestion, sometimes, will automatically import the symbol for you.
In PyCharm, you'll only get suggestions for symbols available in the current scope, even pressing Ctrl+Space will hint "No suggestions". The weird thing though is that if you ask for PyCharm to autocomplete & auto-import using Ctrl+Space+Space it will complete the typed thing with its best match even if it's not imported, in which case it will even auto-generate an import statement. (The Ctrl+Space+Space thing is discussed in here)
Using Ctrl+Space+Space does makes it a little bit better than having to type the full symbol, wait for it to be marked in red and then using Context Actions to import the symbol. Though it does require you to remember and hit the Keyboard Shortcut and it does not offer a visual list displaying your autocomplete options so it's impossible to know for sure what you will get with it until you do it.
This issue is present since 2017 for me, though I decided to post it here since it still annoys me a good deal.
Thanks,
Rodrigo Oliveira.
请先登录再写评论。
Oh, and just to note: this has never worked for me in PyCharm and everything seems fine under **File | Settings | Editor | General | Code Completion** since they are just the default values. As I said, PyCharm is able to generate the complete import statement and even ask me from where to import the symbol once it is fully typed and red-marked when I use context actions. It is able to autocomplete the symbol when it is half-typed using Ctrl+Space+Space. Though it doesn't suggest code completions for non-imported symbols in the list that appears above the caret.
Hi, could you provide an example of the issue (steps to reproduce, the expected and actual result?)
It's simple, just start a new pure-Python project:
proj/
- __init__.py
- a.py
- b.py
In a.py put the following:
```
class TestAutocomplete:
pass
```
In b.py start typing `foo = TestA` and then the issue appears:
- Expected behaviour: a list of auto-completion options should be shown, suggesting the class TestAutocomplete from `proj.a`. Upon selecting an option the symbol should be also auto-imported
- Actual behaviour: no auto-completion is shown although PyCharm is clearly able to do it because pressing Ctrl+Space+Space will auto-complete the symbol and import it as expected. Also, if you type the full and correct name of the symbol and hit Ctrl+Enter it will show the option to import the symbol correctly.
I second this problem.
Even a simpler example:
https://www.jetbrains.com/pycharm/guide/tips/generate-imports-while-typing/?playlist=A
Impossible to reproduce this tip: when I begin to type `choi` then press Ctrl - Space - Space hoping to complete it `choices` from `random` nothing shows up…
Hello Yahya-abou-imran ,
Pleas try **File | Invalidate Caches/Restart** from the main menu. If you have any third-party plugins please try disabling them.
If it does not help, please submit a ticket https://youtrack.jetbrains.com/issues/PY
Just tried disabling all installed Plugins, then invalidate caches & restart and the issue is still there. Also, I've tried using the system's Python 3.8 (under Ubuntu 20.04) instead of the one from the virtualenv, and the issue still remains. When I have the time I'll submit a ticket for this.
As of today this problem does not seem resolved.
I develop with python and django and noticed the django modules are never suggested !
Hi G Bronzini,
It might be the following issue https://youtrack.jetbrains.com/issue/PY-37744/django-stubs-breaks-code-completion
Do you have django-stubs installed?
No django-stubs installed. The problem is not the autocomplete but rather that pycharm does not seem to find any django modules when suggesting the imports.
Hello G Bronzini,
I see. May I ask you to submit a bug report on https://youtrack.jetbrains.com/issues/PY ? Please attach a couple of screenshot examples which present the problem.
Created https://youtrack.jetbrains.com/issue/PY-62727/Failure-to-list-Django-imports thanks