导入错误:没有名为elementtree.ElementTree的模块

0 投票
1 回答
2337 浏览
提问于 2025-04-17 13:55

我正在使用 Python 2.7,并且接手了一个其他开发者的项目。我只是想让它能正常编译,但遇到了导入错误,因为之前的开发者使用了 "import elementtree.ElementTree as ET"。所以我正在把这段代码替换成 "import xml.etree.ElementTree as ET"。

但是现在我遇到了一个文件,还是无法编译。以下是错误追踪信息:

C:\Users\Daniel\Documents\Time clock\source\TimeClock>python timeclock.py
Traceback (most recent call last):
  File "timeclock.py", line 30, in <module>
    from CheckHoursDialog import CheckHoursDialog
  File "C:\Users\Daniel\Documents\Time clock\source\TimeClock\CheckHoursDi
alog.py", line 11, in <module>
    from StudentEarningReport import StudentEarningReport
  File "C:\Users\Daniel\Documents\Time clock\source\TimeClock\StudentEarni
ngReport.py", line 10, in <module>
    import elementtree.ElementTree as ET
ImportError: No module named elementtree.ElementTree

有没有人能给我一些建议?

这是文件的前40行内容。

"""StudentEarningReportPanel

Panel to show what students earned, based on the StudentEarningReport.
"""
__history__ = """History:
3/18/2010: Added ShowXML button
"""
import wx
import wx.lib.scrolledpanel as scrolled


from datetime import datetime as DT
import xml.etree.ElementTree as ET



from PyCollapsiblePane import PyCollapsiblePane as PCP
#~ try:
    #~ from agw import pycollapsiblepane as PCP
#~ except ImportError: # if it's not there locally, try the wxPython lib.
    #~ import wx.lib.agw.pycollapsiblepane as PCP

CP = PCP.PyCollapsiblePane



class ReportPanel(scrolled.ScrolledPanel):
    """ReportPanel(parent, node)
    Parent is the wx.Window-based parent.
    Node is an ElementTree.Element created by StudentEarningReport.py
    """
    def OnPaneChanged(self, evt=None):
        self.SetupScrolling(scrollToTop=False)

    def __init__(self, parent, node):
        assert ET.iselement(node)
        #~ ET.dump(node)
        self.Elem = node
        scrolled.ScrolledPanel.__init__(self, parent, style=wx.BORDER_SIMPLE)

1 个回答

0

问题在于你已经修复了 StudentEarningReportPanel.py 这个文件,但你导入的 StudentEarningReport.py 文件还没有修复。

撰写回答