Pycharm (Python IDE) doesn't auto complete Dja

2019-01-26 06:10发布

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...)

5条回答
做自己的国王
2楼-- · 2019-01-26 06:20

GOTO File > Settings > Langauges & Frameworks > Python Template languages

Select Django in the Template language drop-down.

Jetbrains Docs > Python Template Languages

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-01-26 06:22

Nothing here worked for me but Enabling Django support in the settings did:

  1. Settings > Languages & Frameworks > Django
  2. Check of "Enable Django Support"
  3. Fill in the information for your project.
查看更多
欢心
4楼-- · 2019-01-26 06:28

Trivial solution that worked for me: start a new django project using pycharm project options. Try auto-completing using a django import module. If it works, switch back to your original project and auto-complete should be working fine.

I still don't understand why this works.

查看更多
混吃等死
5楼-- · 2019-01-26 06:33

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.
查看更多
够拽才男人
6楼-- · 2019-01-26 06:36

I worked out this fix:

  1. Go to Preferences > Project:{YourProject} > Python interpreter.
  2. I saw that the field for "Project interpreter" said "2.7...", but I was coding with python 3.4 and my project was created with python 3.4. Replace the version of python in the "Project interpreter" field with the Python version by means of which you have created your Django project. Apply changes and restart PyCharm.
查看更多
登录 后发表回答