pydev:导入编译模块时出现未定义变量错误
我想将我的 python-IDE 从空闲切换到 pydev (eclipse)。我正在使用几个模块,它们仅作为已编译的字节码(*.pyc)。在空闲状态下,这从来都不是问题,它甚至为那些已编译的模块提供代码补全。但是 pydev 给了我很多“未定义的变量”错误 - 然而代码被正确解释。
有没有办法 pydev 可以像idle一样处理字节码模块?也许没有反编译文件?
I want to switch my python-IDE from idle to pydev (eclipse). I am using a couple of modules which I have as compiled bytecode (*.pyc) only. In idle that was never a problem and it even offers code completion for those compiled modules. But pydev gives me a lot of "undefined variable" errors - however the code is interpreted correctly.
Is there a way pydev can handle bytecode modules the way idle does? Perhaps without decompiling the files?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将模块添加为强制内置。
为此,请进入“设置”→“PyDev”→“解释器”-(Python/Jython/IronPython 视情况而定),选择您正在使用的解释器,并将其添加到“强制内置”选项卡上的列表中(< a href="http://pydev.org/manual_101_interpreter.html#id1" rel="nofollow">查看此处了解更多详细信息)。
(请注意,您可能需要也可能不需要为子包和模块添加多个条目;例如,要使 Fabric 正常工作,需要同时添加
fabric
和fabric.api
)这使得 PyDev 将这些模块加载到解释器中以获取代码完成和错误检查数据,而不仅仅是分析源代码。
我还没有尝试过
.pyc
文件,但它适用于其他事情,比如导入由脚本的__init__.py
动态生成的东西或其他东西(即 Fabric),所以它可能对你有用。(另请参阅此常见问题解答和PyDev 网站上的那个)
Try adding the modules as forced builtins.
To do that, go into Settings → PyDev → Interpreter - (Python/Jython/IronPython as approriate), select the interpeter you're using, and add it to the list on the Forced Builtins tab (look here for more details).
(Note that you may or may not have to add multiple entries for subpackages and modules; for example to get Fabric working properly one needs to add both
fabric
andfabric.api
)That makes PyDev load those modules into an interpreter to get code-completion and error checking data, rather than just analysing source code.
I've not tried it for
.pyc
files, but it works for other things like importing something that's generated dynamically by a script's__init__.py
or something (ie fabric) so it might work for you.(see also this FAQ and that one on the PyDev site)