PyDev 的导入错误

发布于 2024-09-25 19:54:17 字数 652 浏览 1 评论 0原文

我使用 PyDev/Eclipse 已有几个月了,并且在导入时遇到了相同的错误: PyDev 在导入中用红色下划线并表示 Unresolved import xxx ;发现于 yyy。当我单击 yyy eclispe 时,找到并打开模块的实现。 (PyDev 只是告诉我它找不到模块 xxx,并且在同一条消息中它可以找到它!)

模块 xxx 位于 eclipse 的 PYTHONPATH 中。当我“探索”该项目的解释器时,我可以毫无问题地找到它。 当我尝试执行(从 eclipse)时,我没有收到任何错误并且工作正常。

有时,错误消息会保留几天,然后消失。有时,它不会。我尝试刷新项目,但对此没有影响。 有时,它在一个项目中运行良好,我可以使用自动完成功能,但它在另一个项目(相同的解释器)中不起作用......

我只是无法理解发生了什么?

到目前为止,我已经忽略了这些错误,因为一切都完全正常,但有时,在工作时出现红色标记“错误”有点令人不安。

您是否找到了避免 PyDev 中这些错误的方法?这是“正常”吗?有没有办法强制 PyDev“刷新”?

谢谢。

参考文献:

  • python 2.4.4(从源代码构建)
  • PyDev v 1.6.0 2010071813

I am using PyDev/Eclipse for several monthes and I get ever and ever the same bugs with imports:
PyDev underline in red an import and say Unresolved import xxx ; Found at yyy. When I click on yyy eclispe find and open the implementation of the module.
(PyDev just inform me that it can't find the module xxx and in the same message that it can find it !)

The module xxx is in the PYTHONPATH of eclipse. When I "explore" the interpreter of the project, I can find it without any problems.
When I try to execute (from eclipse), I don't get any error and it works fine.

Sometimes, the error message will stay for several days and will disappear. Sometimes, it won't. I've tried to refresh the projects but it has not impact on that.
Somtimes, it works well on a project and I can use autocompletion and it don't work in another project (same interpreter) ...

I just can't understand what is happenning ?

So far, I have ignored these bugs because everything was fully fonctionnal but sometimes, it is a bit disturbing to have red markers "errors" when you are working.

Did you find a way to avoid these bugs in PyDev ? Is it "normal" ? Is there a way to force PyDev to "refresh" ?

Thank you.

References :

  • python 2.4.4 (built from sources)
  • PyDev v 1.6.0 2010071813

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

手长情犹 2024-10-02 19:54:17

如果 PyDev 未缓存新模块,则可能会发生这种情况。例如,在我的新笔记本电脑上,我首先安装了 PyDev/Eclipse,然后安装了 Django 包。这就是 Django 导入被标记为未解决的原因。您可以使用 Pydev > 刷新它解释器 - Python >图书馆>申请。选择您想要“恢复”的解释器(他们可以选择更好的词),然后单击“确定”。然后 PyDev 将重新解析所有已安装的模块。

我使用的是 PyDev 的夜间版本,但任何 1.6.x 版本都应该可以正常工作。如果这没有帮助,请删除解释器配置并创建一个新配置。

This can happen if new modules are not cached by PyDev. For example, on my new laptop I first set up PyDev/Eclipse and later installed the Django package. That's why Django imports were marked as unresolved. You can refresh it using Pydev > Interpreter - Python > Libraries > Apply. Select the interpreter you want to "restore" (they could have chosen a better word) and click OK. PyDev will then reparse all installed modules.

I'm using the nightly version of PyDev, but any 1.6.x version should work correctly. If that doesn't help, remove the interpreter configure and create a new one.

话少心凉 2024-10-02 19:54:17

您可以尝试在 Preferences > 中刷新 PYTHONPATH派德夫解释器 - Python 并为您的解释器选择 AutoConfig,然后手动为您的 PYTHONPATH 选择库。

但这是相当激进的解决方案。在大多数情况下,进行无关紧要的更改(例如添加空格)并保存文件应该可行。如果没有,您还可以尝试临时删除,然后重新添加导致问题的文件中的导入。

You can try refreshing your PYTHONPATH in Preferences > Pydev > Interpreter - Python and selecting AutoConfig for your interpreter, then manually choosing the libraries for your PYTHONPATH.

This is pretty radical solution though. Making an insignificant change (like adding a space) and saving file should work in most cases. If not, you can also try temporary delete and then re-add the imports in file that is causing problems.

打小就很酷 2024-10-02 19:54:17

以防万一其他人遇到此线程但上述答案无法解决问题,请确保您的脚本与您尝试导入的库的名称不同。

Just in case anyone else runs into this thread but above answers don't solve the issue, make sure that your script does not have the same name as the library that you are trying to import.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文