日食 + PyDev 导入错误

发布于 2024-11-19 11:39:20 字数 1580 浏览 2 评论 0原文

我无法让 PyDev on Eclipse 识别已安装的模块 (gensim),该模块在 IDLE 中工作正常。我使用的是 Windows Vista,32 位。 Python 2.7。

我发现这个问题被问到:这里,此处此处,以及此处

推荐的解决方案是转到首选项> pydev >解释器 - python,并删除并重新添加(使用自动配置)python 解释器。我已经这样做了,并重新启动了 Eclipse。在 PYTHONPATH 中,出现 C:\Python27\lib\site-packages\gensim-0.8.0-py2.7.egg,但我仍然遇到导入错误。我的代码是:

from gensim import corpora, models, similarities

这会产生:

Traceback (most recent call last):
  File "C:\Users\Jpan\Documents\workspace\FirstProject\src\gensim.py", line 1, in <module>
    from gensim import corpora, models, similarities
  File "C:\Users\Jpan\Documents\workspace\FirstProject\src\gensim.py", line 1, in <module>
    from gensim import corpora, models, similarities
ImportError: cannot import name corpora

另一个推荐的解决方案是通过单击解释器 - python 屏幕底部的“新文件夹”并导航到 gensim 安装的位置来手动添加文件夹。我也这样做了,并添加了 C:\Python27\lib\site-packages\gensim-0.8.0-py2.7.egg\gensim,其中包含所有必需的 \__init__ .py 文件。但是,我仍然收到 ImportError

对我还可以尝试什么有什么建议吗?

I am having trouble getting PyDev on Eclipse to recognize installed modules (gensim), which work fine in IDLE. I am using Windows Vista, 32-bit. Python 2.7.

I have found this question asked: here, here, here, and here.

The recommended solution is to go to preferences > pydev > interpreter - python, and remove and re-add (w/ Auto Config) the python interpreter. I have done this, and have restarted Eclipse. In PYTHONPATH, C:\Python27\lib\site-packages\gensim-0.8.0-py2.7.egg, appears, but I still run into the import error. My code is:

from gensim import corpora, models, similarities

And this yields:

Traceback (most recent call last):
  File "C:\Users\Jpan\Documents\workspace\FirstProject\src\gensim.py", line 1, in <module>
    from gensim import corpora, models, similarities
  File "C:\Users\Jpan\Documents\workspace\FirstProject\src\gensim.py", line 1, in <module>
    from gensim import corpora, models, similarities
ImportError: cannot import name corpora

Another recommended solution is to manually add the folder by clicking "New Folder" in the bottom part of the interpreter - python screen and navigating to the location where gensim installed. I have also done this, and added C:\Python27\lib\site-packages\gensim-0.8.0-py2.7.egg\gensim, which has all the necessary \__init__.py files. But, I still get the ImportError.

Any suggestions for what else I could try?

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

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

发布评论

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

评论(1

凉城已无爱 2024-11-26 11:39:21

这独立于 Eclipse/PyDev。以任何其他方式运行代码都会遇到相同的错误。您的模块导入gensim。 PYTHONPATH 上的第一个条目是当前目录,您的模块名为 gensim.py,因此您的模块尝试导入iteself。因为导入被缓存,所以您不会陷入无限递归,而是获得对包含...任何内容的模块的引用,尤其是不包含您期望从“真实”gensim 模块中获得的内容。

错误消息应该提到这种可能性,这种情况非常常见。解决方案是重命名您的文件。

This is independent of Eclipse/PyDev. You'll get the same error running the code in any other way. Your module imports gensim. The first entry on the PYTHONPATH is the current directory, and your module is called gensim.py, so your module attempts to import iteself. Because imports are cached, you don't get into infinite recursion but get a reference to a module containing... nothing, especially not the things you expected from the "real" gensim module.

The error message should mention this possibility, it's incredibly common. The solution is to rename your file.

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