Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

import error?

rulrul Posts: 8Member
when i try to run my code, i get a -> importerror: no module named dom. the first few lines of my code is below,

import os
import time
import urllib
from xml.dom import minidom
from xml.sax.saxutils import escape

why is there such an error? i tried a fresh install of python 2.4 but the same error occurs. i've uninstalled 2.4 and reinstalled 2.3.5. can anyone help?

Comments

  • infidelinfidel Posts: 2,900Member
    : when i try to run my code, i get a -> importerror: no module named dom. the first few lines of my code is below,
    :
    : import os
    : import time
    : import urllib
    : from xml.dom import minidom
    : from xml.sax.saxutils import escape
    :
    : why is there such an error? i tried a fresh install of python 2.4 but the same error occurs. i've uninstalled 2.4 and reinstalled 2.3.5. can anyone help?

    Just to be clear, you get the error with 2.4 but not with 2.3.5?

    Did you install any other packages with 2.3.5, like PyXML or anything like that?


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • rulrul Posts: 8Member
    : : when i try to run my code, i get a -> importerror: no module named dom. the first few lines of my code is below,
    : :
    : : import os
    : : import time
    : : import urllib
    : : from xml.dom import minidom
    : : from xml.sax.saxutils import escape
    : :
    : : why is there such an error? i tried a fresh install of python 2.4 but the same error occurs. i've uninstalled 2.4 and reinstalled 2.3.5. can anyone help?
    :
    : Just to be clear, you get the error with 2.4 but not with 2.3.5?
    :
    : Did you install any other packages with 2.3.5, like PyXML or anything like that?
    :
    :
    : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    :
    : [code]
    : $ select * from users where clue > 0
    : no rows returned
    : [/code]
    :
    :

    i still get the error with 2.3.5. the funny thing is, the line "from xml.dom import minidom" works fine when i type it in IDLE. but when i open my program in IDLE, it wont run, giving the error mentioned above. i installed wxpython and py2exe but i remember trying to run the program with only python installed but still getting the error. any ideas?
  • infidelinfidel Posts: 2,900Member
    : i still get the error with 2.3.5. the funny thing is, the line "from xml.dom import minidom" works fine when i type it in IDLE. but when i open my program in IDLE, it wont run, giving the error mentioned above. i installed wxpython and py2exe but i remember trying to run the program with only python installed but still getting the error. any ideas?

    Wow, if it works interactively but not from a script then I am stumped. I would recommend posting a message to comp.lang.python. You can use Google Groups to do it if you've never posted to usenet before.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • DrostDrost Posts: 24Member
    [b][red]This message was edited by Drost at 2005-3-31 6:22:44[/red][/b][hr]
    [b][red]This message was edited by Drost at 2005-3-31 6:21:50[/red][/b][hr]
    : : : when i try to run my code, i get a -> importerror: no module named dom. the first few lines of my code is below,
    : : :
    : : : import os
    : : : import time
    : : : import urllib
    : : : from xml.dom import minidom
    : : : from xml.sax.saxutils import escape
    : : :
    : : : why is there such an error? i tried a fresh install of python 2.4 but the same error occurs. i've uninstalled 2.4 and reinstalled 2.3.5. can anyone help?
    : :
    : : Just to be clear, you get the error with 2.4 but not with 2.3.5?
    : :
    : : Did you install any other packages with 2.3.5, like PyXML or anything like that?
    : :
    : :
    : : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    : :
    : : [code]
    : : $ select * from users where clue > 0
    : : no rows returned
    : : [/code]
    : :
    : :
    :
    : i still get the error with 2.3.5. the funny thing is, the line "from xml.dom import minidom" works fine when i type it in IDLE. but when i open my program in IDLE, it wont run, giving the error mentioned above. i installed wxpython and py2exe but i remember trying to run the program with only python installed but still getting the error. any ideas?
    :

    Do you have a directory called xml beside your script? Which has "accidentally" an __init__.py in it? Which would mean to the parser that you want to use that self-made-module-which-consists-of-several-files (what are those actually called?)instead of the real one.

    Drost



  • rulrul Posts: 8Member
    : Do you have a directory called xml beside your script? Which has "accidentally" an __init__.py in it? Which would mean to the parser that you want to use that self-made-module-which-consists-of-several-files (what are those actually called?)instead of the real one.
    :
    : Drost

    no i dont. it wont have anything to do with how i name my files would it? i save my code as xml.py but python will look in its lib directory when i import right? i have no other files except for my xml.py
  • DrostDrost Posts: 24Member
    : : Do you have a directory called xml beside your script? Which has "accidentally" an __init__.py in it? Which would mean to the parser that you want to use that self-made-module-which-consists-of-several-files (what are those actually called?)instead of the real one.
    : :
    : : Drost
    :
    : no i dont. it wont have anything to do with how i name my files would it? i save my code as xml.py but python will look in its lib directory when i import right? i have no other files except for my xml.py
    :

    Please rename it then to something else. IIRC the parser searches for external modules firstly in the same directory, the running script is in and only when it's not there would it look for it in different places...

    Which in my opinion is a "Good Thing(TM)".

    Drost
  • rulrul Posts: 8Member
    : Please rename it then to something else. IIRC the parser searches for external modules firstly in the same directory, the running script is in and only when it's not there would it look for it in different places...
    :
    : Which in my opinion is a "Good Thing(TM)".
    :
    : Drost

    ok i've renamed it and it works! i always thought python would still be able to find the required modules no matter how you name ur script?! well, thanks for all the help!
  • infidelinfidel Posts: 2,900Member
    : : Please rename it then to something else. IIRC the parser searches for external modules firstly in the same directory, the running script is in and only when it's not there would it look for it in different places...
    : :
    : : Which in my opinion is a "Good Thing(TM)".
    : :
    : : Drost
    :
    : ok i've renamed it and it works! i always thought python would still be able to find the required modules no matter how you name ur script?! well, thanks for all the help!

    Good job, Drost!

    Python has to follow certain consistent rules when looking up objects by name. You asked it for something named "xml" and it found the first one it came across in its path of places to look (the current directory is first). Note that you can actually change the sys.path variable at runtime to let it look in other places.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

Sign In or Register to comment.