Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pycharm (Python IDE) doesn't auto complete Django modules

My Python IDE (pycharm) has stopped auto completing my modules (suggestions). I get unresolved references after every django module I try to import so:

from django - works, however soon as I add a 'dot' it fails so from django.db import models gives me unresolved errors...

The ackward thing is after compiling references DO work.

I discovered that all my __init__.py files (everywhere) no longer are marked with python icon and are now notepad icons. Also opening init files in my interpreter gives non-color marked up text (no syntax highlighting). So I think Python doens't recognizes these files.

My python interpreter is python 2.6.1 with Django 1.2.4 and my django is installed under: /Lib/python/2.6/site-packages (full directories, not egg)

When I unfold sitepackages from external libraries within the IDE I do see colored mark up for all .py files EXCEPT __init__.py files. Hence thats where the issue lives.

(I have found posts on google for similar problems but no answers...)

like image 920
deven677 Avatar asked Feb 05 '11 10:02

deven677


People also ask

Why Autocomplete is not working in PyCharm?

You need to go into the project settings and configure the interpreter to point at the virtualenv. PyCharm will then index the interpreter and allow you to autocomplete. The virtualenv may be auto-detected in the dropdown menu on the left.

How do I turn on autocomplete in PyCharm?

Go to Settings / Preferences | Editor | General | Postfix Completion and select the Enable postfix completion checkbox.

How do I enable Django in PyCharm?

To enable Django support, follow these steps: Open the project Settings/Preferences dialog ( Ctrl+Alt+S ) and navigate to the Languages & Frameworks | Django page. Make sure that the checkbox Enable Django support is selected. Apply changes (if any) and close the dialog.

How does PyCharm detect Django?

If you cannot print the Django version from the python console in Pycharm, go to settings>Project:project_name>project Interpreter and from the list of installed packages see the installed Django and it's version for that project.


1 Answers

I had exactly the same issue and couldn't find a definitive answer. Just invalidating caches didn't work for me. The problem lies in the fact that, at some point, __init__.py files got registered as text files and messed up the indexing. I worked out this fix:

  • Preferences > File Types > Text Files.
  • Remove __init__.py from the list of registered patterns. Apply.
  • Wait for your indexes to re-build.
  • (If it's still not working) File > Invalidate caches & restart.
like image 125
stevenholmes Avatar answered Oct 14 '22 11:10

stevenholmes