Eclipse XLRD, XLWT Import Error

ぐ巨炮叔叔 提交于 2019-12-13 19:59:43

问题


I downloaded the latest Enthought EPD python distribution (academic), which comes with python 2.7. I am using Eclipse as my IDE.

Eclipse is set up to use this instance of Python. I ran the "images.py" example file under XLWT.

"images.py":

from xlwt import Workbook
w = Workbook()
ws = w.add_sheet('Image')
ws.insert_bitmap('python.bmp', 0, 0)
w.save('images.xls')

and Eclipse returned:

Traceback (most recent call last):
  File "C:\Documents and Settings\Username\workspace\XLRDXLWT\src\xlwt\images.py", line 1, in 
<module>
    from xlwt import Workbook
ImportError: cannot import name Workbook

Similar problem with any other example I try to run in XLRD, XLUTILS.


回答1:


Yes, indeed, "someone" helped you with the answer.

It's nothing to do with xlrd, xlwt, xlutils, or Eclipse.

In general, if you put a script that does import foo into a directory named foo, Python is likely to try to import foo from that directory, and fail.

Solution: Don't do that. Rename your script directory to foo_examples or foo_scripts or suchlike.



来源:https://stackoverflow.com/questions/5666272/eclipse-xlrd-xlwt-import-error

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