IntelliJ IDEA auto import doesn't work for Python

Viewed 46

I have using IntelliJ IDEA for php developement and it works without a issue. I have just started doing some Django coding and I encountered this issue where autocomplete doesn't work for imports.

I'm using Python 3.9 with Django 4.0.6 and I use pipenv for virtual environment.

I'm trying to do some basic imports like importing HttpResponse from django.http. I expect the IDE to suggest the import as I'm typing (like for php) but it doesn't. for it to work I have to press control+space 2 times and then it shows the suggestions (If I just pres it 1 time it says "No suggestions") or I can type everything then press option+return and it suggests to import it then.

Auto Import setting for python is like this:

My Auto Import fsetting

Code Completion setting doesn't have a Python section but the general area is set up like this:

Code Completion setting

Project setting seems to be correct and does have the django module:

enter image description here

enter image description here

and this is my .iml file in the .idea folder:

<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
  <component name="FacetManager">
    <facet type="django" name="Django">
      <configuration>
        <option name="rootFolder" value="$MODULE_DIR$" />
        <option name="settingsModule" value="django_app/settings.py" />
        <option name="manageScript" value="manage.py" />
        <option name="environment" value="&lt;map/&gt;" />
        <option name="doNotUseTestRunner" value="false" />
        <option name="trackFilePattern" value="migrations" />
      </configuration>
    </facet>
    <facet type="Python" name="Python">
      <configuration sdkName="Pipenv (social-media)" />
    </facet>
  </component>
  <component name="NewModuleRootManager" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$" />
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="library" name="Pipenv (social-media) interpreter library" level="application" />
  </component>
</module>
1 Answers

I discussed it over at jetbrain support forum and I'll answer this in case anyone else is wondering.

This is what initially confused me: I am using phpstorm for many years at my job and for php as long as I require a library with composer it's instantly available for auto complete/import as I type it. so i assumed the same behavior should apply to other Jetbrain products by default.

Turned out this is not the case and the behavior I described at the question here IS how Pycharm or IntelliJ+python behaves by design. auto complete/import only works for builtin libs and the libs you import in the file you are writing. for example if you have this import in your file: from django.http import *, and then you type HttpRequest it will suggest it correctly but if the import is not there you have to hold 'Control' key and press 'Space' key twice for autocomplete tooltip to show the suggestions.

You can read the full discussion here:

https://intellij-support.jetbrains.com/hc/en-us/community/posts/360007264739-python-autocomplete-not-working?page=1#community_comment_6656007978642

Related