Pycharm doesn't detect / suggest modules, classes, or functions to import when typing

When using the other IDEs (webstorm, IDEA, phpstorm), if I start typing a class name, or something I want to import, it will immediately make suggestions of matching symbols to import. Pycharm no longer does this.  Did i accidentally change a setting somewhere, or is this a bug?

1
15 comments

Code completion suggestions depend on the properly configured project interpreter. What interpreter type do you use? Does the code run without errors? 

In general, check your settings under **File | Settings | Editor | General | Code Completion**, in case you accidentally disabled suggestions.

-1

thanks for your reply

i have projects with virtualenv, pipenv, and venv. it doesn't work for any of them. I haven't worked on these projects in any significant capacity this year, so im not sure when it stopped working properly. (possibly related, however, i just started a new project with pipenv and it never seems to detect packages installed via the terminal)

and i double-checked the settings. it's enabled. it's not that it doesn't show suggestions at all. it only does it for builtins as i type. once i type a complete symbol name and pause, it offers to import it

0

oh, and yes, all projects run as expected

0

If it's about built-ins, try File > Invadidate caches/restart, and also Reload interpreter paths in the interpreter settings. Make sure you don't have unnecessary folders (like venv) marked as excluded in project structure.

If nothing helps, try creating a new project with new virtualenv environment and see if the issue is still reproduced. Provide a code snippet, I will try to check locally just in case.

3

Sorry for my delayed response, I was away for a bit.

> If it's about built-ins, 

It's about everything other than built-ins. It doesn't even detect modules in python's stdlib as i type. 

> try File > Invadidate caches/restart, and also Reload interpreter paths in the interpreter settings. Make sure you don't have unnecessary folders (like venv) marked as excluded in project structure.

I have tried all of this. Unfortunately it hasn't helped

> If nothing helps, try creating a new project with new virtualenv environment and see if the issue is still reproduced. Provide a code snippet,

I'm not sure what I could even provide. a minimal setup is an empty file with one installed library

Maybe my problem isn't clear.  I'll provide screenshots with python's behavior (trying to import a class from a django module) and one with javascript's expected behavior (importing an Observable from rxjs) (And like I said, it works properly for Dart, Java, kotlin, etc. I just already had this project open)

In python's behavior, I expect it to offer to import `ModelAdmin` before I finish typing the full class name. You see in the javascript example that a list is shown to import from various sources

0

If you're starting with a blank file, you first need to import a module/library before you can have autocomplete. I don't see keyword "import" in your example.

Please provide steps to reproduce the issue starting from creating a new project.

0

the javascript example also doesn't have an import statement. it's just a blank file.  im not looking for code completion in the traditional sense. im looking for import suggestions, which is what happens when writing java, kotlin, javascript, typescript, php, etc. all of them detect what should be imported

1

Steps to reproduce:

1. Create new project

2. Create python file

3. Type "joi"

 

Expected behavior: a context menu will automatically open with "Import from..." in the title, offering to import "os.path.join()" 

Actual behavior: Nothing happens. Once "join" is fully typed out, alt+enter will display an option to import the function

0

I don't think PyCharm ever offered imports from incomplete entries like "joi". I think it's quite expected that you have to fully type the function/method/class name before IDE can offer you the import. Oh the other hand, for already imported or otherwise referred objects, you will get the suggestion without fully typing it out.

Anyway, you can submit a feature request, I guess.

0

admittedly I haven't started a new python project in a couple years. i've only been maintaining things i'd already created. so it's entirely possible i've expected functionality from the other jetbrains IDEs to exist in pycharm. if that's the case, then yes, i'll file a feature request

but i disagree that it's expected to fully type any symbol because that's the exact problem code completion solves

thank you for all your support

0

Agreed. I do a lot of TypeScript work in WebStorm, and it's so useful that the IDE starts suggesting symbols to import before you finish typing its name. In PyCharm, you need to remember how a symbol is cased etc. and then trigger the import dialog for it to help at all, which is really annoying. In WebStorm, I can type "AB" and it will autocomplete "AppBar" and take care of the import if it's not already there. In PyCharm, I end up quickly doing a symbol search to double check my spelling, then type it out, and finally option+enter to trigger the import, and it's a huge pain by comparison, especially since the symbol search shows me that PyCharm could easily do this (since the symbol search is performant).

2
Avatar
Permanently deleted user

This is implemented now!

Blog post - https://blog.jetbrains.com/pycharm/2018/11/let-pycharm-do-your-import-janitorial-work/

TLDR; use ctrl+space+space to bring up autocomplete for non-imported symbols.

3

Ctrl+Space+Space does help though it doesn't completely solve the issue: unimported symbols won't show up in the autocomplete suggestions list, even though Ctrl+Space+Space works (without any visual list to choose from though). Since I don't know if this is still an issue for OP I've posted a new issue: https://intellij-support.jetbrains.com/hc/en-us/community/posts/360009733119-PyCharm-doesn-t-display-suggestions-for-non-imported-symbols-while-typing?page=1#community_comment_360002235040

0

i faced the same problem, only thing that you have to do is close your current project and go to your project folder there you can see a folder called .idea delete that folder and open your project again. so you will not see unimportant suggestions. next time make sure to include the file in gitignore file..

0

Had the same issue today, I had neither context actions nor warning for unimported symbols.

Turns out I hadn't configured my project interpreter 

0

Please sign in to leave a comment.