pylint 不喜欢 pkg_resources.resource_filename
在我的脚本中我使用:
python 从 pkg_resources 导入资源文件名 。
PyDev 和 pylint 0.23 都抱怨此处未解决的导入
<代码> E0611 模块“pkg_resources”中没有名称“resource_filename” 据我
了解,发生这种情况是因为 PyDev 和 pylint 都只执行源代码分析,而不实际尝试解析/编译它。显然,pkg_resources 做了一些特殊的事情来定义 pkg_resources。包装和符号当然在那里,并且整个事情运行得很好。有两个问题:
- 我怎样才能让 Eclipse 和 PyDev 相信他们都错了?
- 首先是什么导致了这个问题?我还没有发现其他人有这种问题,我怀疑我的情况有些独特...:)
Python 2.7.1(在 OSX 下),分发 0.6.19。
In my script I use:
python
from pkg_resources import resource_filename
Both PyDev and pylint 0.23 complain about unresolved import here.
E0611 No name 'resource_filename' in module 'pkg_resources'
As I understand, this happens due to the fact that both PyDev and pylint perform only source code analysis, without actually trying to parse/compile it. And apparently pkg_resources
does something special to define pkg_resources
. The package and symbol are of course there, and whole thing works just fine. Two questions:
- How can I convince both Eclipse and PyDev that they're mistaken?
- What causes the problem in the first place? I haven't found other people having this kind of problem, and I doubt my situation is somewhat unique... :)
Python 2.7.1 (under OSX), distribute 0.6.19.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过修改项目的 pydev python 解释器定义来加载麻烦的动态模块。 配置“强制内置”的默认列表以包含您使用的动态生成的定义。强制内置是通过剔除和加载/检查动态生成的类来生成的。
在 python 解释器定义
(preferences => pydev =>terpreters => pythonterpreter)
中,为 pydev 项目选择当前使用的解释器。选择强制内置
选项卡。按New...
按钮,并将pkg_resources
添加到列表中。我已经做到了这一点,现在我的错误消失了,并且方法的自动完成对于我的项目来说工作正常。我正在使用 python 2.7.9、pydev 3.3.3 和 eclipse kepler r2。
对于 pylint,您可以在项目的 pylint 配置中全局禁用警告 ,对于整个文件,或者对于其使用的一个实例。您可以在文件开头添加 # pylint:disable=E1101 注释以针对该模块禁用它,或者在您使用它的上方行中仅针对该实例禁用它。还有一种可能很耗时的方法手动提示 pylint 您的类具有特定方法。
You can load troublesome dynamic modules by modifying your project's pydev python interpreter definition. Configure the default list of 'forced built-ins' to include dynamically generated definitions you use. Forced built-ins are generated by shelling out and loading/inspecting dynamically generated classes.
In the python interpreter definition
(preferences => pydev => interpreters => python interpreter)
, select your currently used interpreter for your pydev project. Select theForced Builtins
tab. Press theNew...
button, and addpkg_resources
to the list.I've done this, and now my errors are gone, and auto-complete of methods works ok for my project. I'm using python 2.7.9, pydev 3.3.3, and eclipse kepler r2.
For pylint, you can disable the warning globally in your project's pylint config, for the entire file, or for one instance of its use. You can add a
# pylint: disable=E1101
comment at start of your file to disable it for that module, or on on the line above where you use it to just disable it for that instance. There's also a possibly time-consuming way to manually hint to pylint that your class has specific methods.我也有同样的问题。对于 Pydev,我在 pydev.org 上找到了答案:转到错误行,按 ctrl-1,然后选择“未定义变量”。然后它会附加一个
#@UndefinedVariable
注释,错误就会消失。对于 pylint,禁用 E1101 就可以了,pragma
# pylint:disable=E1101
。 Pylint 编译指示只需处于相同的缩进级别,但 pydev 注释必须位于同一行。我的评论有点混乱的函数变成了:I had the same problem. For Pydev I found the answer on pydev.org: Go to the error line, hit ctrl-1, and select 'undefined variable'. It will then append a
#@UndefinedVariable
comment, and the error goes away.For pylint, disabling E1101 does the trick, pragma
# pylint: disable=E1101
. Pylint pragmas just need to go at the same indent level, but the pydev comment had to be on the same line. My somewhat comment-cluttered function became: