Pycharm(Python IDE)不会自动完成 Django 模块 [英] Pycharm (Python IDE) doesn't auto complete Django modules

查看:30
本文介绍了Pycharm(Python IDE)不会自动完成 Django 模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Python IDE (pycharm) 已停止自动完成我的模块(建议).在我尝试导入的每个 django 模块之后,我都会得到未解析的引用:

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 - 有效,但是只要我添加一个点"它就会失败,所以 from django.db import models 给了我未解决的错误...

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.

我发现我所有的 __init__.py 文件(无处不在)不再标有 python 图标,现在是记事本图标.在我的解释器中打开初始化文件也会给出非颜色标记的文本(没有语法突出显示).所以我认为 Python 无法识别这些文件.

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.

我的 python 解释器是 python 2.6.1 和 Django 1.2.4,我的 django 安装在:/Lib/python/2.6/site-packages(完整目录,不是egg)

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)

当我从 IDE 中的外部库展开站点包时,我确实看到了所有 .py 文件的彩色标记,除了 __init__.py 文件.因此,这就是问题所在.

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

推荐答案

我遇到了完全相同的问题,但找不到明确的答案.只是使缓存无效对我不起作用.问题在于,在某些时候,__init__.py 文件被注册为文本文件并弄乱了索引.我解决了这个问题:

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:

  • 首选项 > 文件类型 > 文本文件.
  • 从注册模式列表中删除 __init__.py.申请.
  • 等待您的索引重新构建.
  • (如果它仍然不起作用)文件 > 使缓存无效 &重新启动.

这篇关于Pycharm(Python IDE)不会自动完成 Django 模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆