PyLint 因多次 Django 导入而失败
我正在使用 PyLint,
pylint -e app/views.py
给我错误,例如
E: 3: No name 'shortcuts' in module 'django'
E: 7: No name 'db' in module 'django'
But Passs for other django import。由于它传递给其他 Django,导入 Django 位于我的 pythonpath 上。
I am using PyLint,
pylint -e app/views.py
Gives me errors like
E: 3: No name 'shortcuts' in module 'django'
E: 7: No name 'db' in module 'django'
But passes for other django imports. Since it passes for other Django import Django is on my pythonpath.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想我已经弄清楚了——如果您跳入 python 会话并实际尝试从 django.db 导入任何内容,
您将收到有关 DJANGO_SETTINGS_MODULE 未设置的错误。设置环境变量并将其指向您的
settings.py
(如app.settings
) 应该会为您修复错误。当我在 Eclipse/PyDev 配置中尝试此操作时,我必须禁用 pylint、构建,然后重新启用 pylint 以最终清除这些错误。
I think I figured it out -- if you jump into a python session and actually try to import anything from django.db
you'll get an error about
DJANGO_SETTINGS_MODULE
not being set. Setting the environment variable and pointing it to yoursettings.py
likeapp.settings
should fix the error for you.When I tried this in an Eclipse/PyDev config I had to disable pylint, build, then re-enable pylint to finally clear out those errors.
您是否尝试过 djangolint,它是一个针对 Django 的 Pylint 包装器设置?
Have you tried djangolint, which is a wrapper around Pylint with Django-specific settings?