ImportError: No module named dom.minidom
I Thought, I would try my hand at XML parsing with the python DOM. Whatever programming llanguage you use the DOM pretty much the the same. However things didn’t get off to an auspicious start. Even the sample code on the python docs didn’t work and produced an error:
Traceback (most recent call last):
File “/var/www/clients/work/python/xml.py”, line 3, in <module>
from xml.dom.minidom import parse, parseString
File “/var/www/clients/work/python/xml.py”, line 3, in <module>
from xml.dom.minidom import parse, parseString
ImportError: No module named dom.minidom
Then I saw a suggestion saying try from xml.dom.minidom import * . I didn’t see how that will work but gave it a try anyway with no luck. I next checked to see if I have libxml2-python I thought to update it and python to see if it will solve it – it didn’t.
Next I tried the interpreter (just invoking python from the command line) and cutting and pasting the code there – whoa that works! Next I tried `cat xml.py | python` and lo and behold that works too. Then I noticed that a file named xml.pyc is being created by the interpreter and being left behind. I suspected that the filename or the way the interpreter is being executed might have something to do with.
A post by one Matt Mower confirmed my fears: The python script being named as xml.py causes the intepreter to get confused. It’s conflicting with the python module named xml (in java we call these packages) in the library. Renaming the file as my_domxml.py and deleting the xml.pyc did the trick. Note that if you just rename the file it’s not going to work the .pyc file will continue to cause trouble.
So I guess whenever I see an ImportError: No module named xxx I should immidiately check my choice of filename.

sir, you have helped me greatly.
my file was also named xml.py, i owe you some beers.
dude, you rock I owe you a good bottle scotch
you are my hero man
Hi there,
maybe this comment makes this thread easier to find:
“ImportError: No module named dom”
when trying to execute:
“python xml.py”
-> rename your xml file to s.th. different than “xml.py” then it will work
no need to install pyXML!!!
Thank you for this post!!!!
DerMac, thanks for summarizing
no kidding, great find, saved me a ton of time. Thanks!
wow,after spending nearly one hour to solve this problem, google suggest this blog… thanks a lot
Really very very smart! thank you a lot
thanks ,it’s very useful
god bless you!
Thank you verry much, you save me a lot of time.
Same problem here, thanks for blogging about it!
Thanks a lot mate saved me a lot of time
Thank you!
Thanks it is very helpful …