Eclipse + PyDev ImportError

Deadly 提交于 2019-12-11 07:18:31

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/6615569/eclipse-pydev-importerror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!