Pycharm(Python IDE)不会自动完成 Django 模块
我的 Python IDE (pycharm) 已停止自动完成我的模块(建议)。在尝试导入每个 django 模块后,我都会收到未解析的引用,因此:
from django
- 有效,但是一旦我添加“点”,它就会失败,因此 from django.db import models
给了我未解决的错误...
令人尴尬的是在编译参考文献之后确实起作用了。
我发现我的所有 __init__.py
文件(到处)不再用 python 图标标记,现在是记事本图标。另外,在我的解释器中打开 init 文件会给出非颜色标记文本(无语法突出显示)。所以我认为Python无法识别这些文件。
我的 python 解释器是 python 2.6.1 和 Django 1.2.4,我的 django 安装在: /Lib/python/2.6/site-packages
(完整目录,而不是 Egg)
当我在 IDE 中从外部库展开 sitepackages 时,我确实看到除 __init__ 之外的所有 .py 文件都有彩色标记.py
文件。这就是问题所在。
(我在谷歌上找到了类似问题的帖子,但没有答案......)
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...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我有完全相同的问题,但找不到明确的答案。仅使缓存无效对我来说不起作用。问题在于,在某些时候,
__init__.py
文件被注册为文本文件并搞乱了索引。我解决了这个问题:__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
from the list of registered patterns. Apply.GOTO 文件> 设置> 语言和语言框架 > Python 模板语言
在模板语言下拉列表中选择 Django。
Jetbrains 文档 > Python 模板语言
GOTO File > Settings > Langauges & Frameworks > Python Template languages
Select Django in the Template language drop-down.
Jetbrains Docs > Python Template Languages
这里没有任何东西对我有用,但在设置中 启用 Django 支持确实:
Nothing here worked for me but Enabling Django support in the settings did:
对我有用的简单解决方案:使用 pycharm 项目选项启动一个新的 django 项目。尝试使用 django 导入模块自动完成。如果有效,请切换回原始项目,自动完成功能应该可以正常工作。
我仍然不明白为什么这有效。
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.
我解决了这个问题:
I worked out this fix:
如果您的项目解释器使用的是 anaconda 等,您应该将其更改为可能位于此路径中的标准 python 解释器(C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\python.exe)
you should just change your project interpreter if it is using anaconda or etc to standard python interpreter which may be located in this path (C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\python.exe)
改变Python解释器
change python interpreter