Search code examples
pycharm

Imported references not found


I am having an issue with the django and rest_framework packages not successfully being imported into PyCharm Professional.

In the project preferences, I have the Django support enabled and the project root, settings file, and manage file properly set. I have the project interpreter using a Virtualenv environment that Pycharm created when I created the project. The project interpreter has all of the packages defined in the requirements.txt. installed.

enter image description here

In most Python files in my project, I am noticing that some of the rest_framework packages can be imported, but others cannot be for no apparent reason. For example, the import from rest_framework.views import APIView is able to import properly, but from django.http import HttpResponse does not import properly and shows Unresolved reference 'HttpResponse'. enter image description here

I notice that the reference to django.http can be resolved, so I am not sure why the reference to HttpResponse cannot be found.

enter image description here

I have tried the following to fix the issue:

  1. Invalidate caches and restart the IDE.
  2. Removing the virtual environment, creating a new one, and restarting the IDE.
  3. Delete the .idea file and re-import the project.

I am really lost as to what to try next. The main benefit to using PyCharm is the IntelliSense features and these do not work properly with all packages not being imported properly. Any recommendations are greatly appreciated :)


Solution

  • Remove __init__.py from Preferences | File type auto-detected by file content | File name patterns

    enter image description here