Have I broken my installation?

Discussion in 'Python' started by Matt Mower, Jun 28, 2003.

  1. Matt Mower

    Matt Mower Guest

    Hi folks,

    I have an old Linux box that I am messing about with Python on. The
    RedHat installed version is 1.5 something so I have built & installed
    2.2.2 in /opt/python.

    I've started trying to play with XML and ran into an error when
    attempting to parse a document:

    >Traceback (most recent call last):
    > File "/mnt/hugedisk/share/MattsMovableType/stb/stb.cgi", line 90, in ?
    > documentElem = parse( rssFile )
    > File "/opt/python/lib/python2.2/xml/dom/minidom.py", line 962, in parse
    > return _doparse(pulldom.parse, args, kwargs)
    > File "/opt/python/lib/python2.2/xml/dom/minidom.py", line 953, in _doparse
    > events = apply(func, args, kwargs)
    > File "/opt/python/lib/python2.2/xml/dom/pulldom.py", line 328, in parse
    > parser = xml.sax.make_parser()
    > File "/opt/python/lib/python2.2/xml/sax/__init__.py", line 93, in make_parser
    > raise SAXReaderNotAvailable("No parsers found", None)
    >xml.sax._exceptions.SAXReaderNotAvailable: No parsers found


    Googling around it seems like I needed to build XML support when I
    built Python. I'm not sure what I should have done differently when I
    built in order to make that happen. The other option on offer
    appeared to be installing PyXML.

    I duly downloaded PyXML 0.8.2 and installed it (again into /opt/python
    using --prefix).

    Now instead of the previous error I get a different problem entirely:

    >Traceback (most recent call last):
    > File "/mnt/hugedisk/share/MattsMovableType/stb/stb.cgi", line 18, in ?
    > from xml.dom.minidom import parse, Document
    > File "./xml.py", line 2, in ?
    > from xml.dom.minidom import parse
    >ImportError: No module named dom.minidom


    I'm pretty sure I had a module dom.minidom before as it is the import
    statement that is raising the exception and it didn't prior to
    installing PyXML, I was previously calling parse() and Document().

    So did I make a mistake installing PyXML? Can anyone advise me on
    what my next steps should be?

    Many thanks,

    Matt

    ---
    Systems Engineer, Hipbone(EMEA) Ltd.
    3000 Hillswood drive, Chertsey, Surrey, KT16 0RS
    Tel: 44-1932-895902 Mob: 44-7980-237-380
    Matt Mower, Jun 28, 2003
    #1
    1. Advertising

  2. Matt Mower <> writes:

    > Googling around it seems like I needed to build XML support when I
    > built Python. I'm not sure what I should have done differently when I
    > built in order to make that happen.


    You should have edited Modules/Setup, to activate pyexpat. Before
    that, you probably should have installed a more recent Expat version
    than the one shipped with Redhat.

    > Now instead of the previous error I get a different problem entirely:
    >
    > >Traceback (most recent call last):
    > > File "/mnt/hugedisk/share/MattsMovableType/stb/stb.cgi", line 18, in ?
    > > from xml.dom.minidom import parse, Document
    > > File "./xml.py", line 2, in ?
    > > from xml.dom.minidom import parse
    > >ImportError: No module named dom.minidom

    >
    > I'm pretty sure I had a module dom.minidom before as it is the import
    > statement that is raising the exception and it didn't prior to
    > installing PyXML, I was previously calling parse() and Document().
    >
    > So did I make a mistake installing PyXML?


    This is uncertain. Does this also happen when you invoke Python from
    the command line? If so, what happens if you do

    import xml
    print xml
    import xml.dom
    print xml.dom
    import xml.dom.minidom
    print xml.dom.minidom

    If not, what happens if you do the same in the CGI script?

    Regards,
    Martin
    Martin v. =?iso-8859-15?q?L=F6wis?=, Jun 28, 2003
    #2
    1. Advertising

  3. Matt Mower

    Matt Mower Guest

    Hi Martin,

    Thanks for responding. My answers are below.

    On 28 Jun 2003 17:53:52 +0200, (Martin v. Löwis)
    wrote:

    >> I'm pretty sure I had a module dom.minidom before as it is the import
    >> statement that is raising the exception and it didn't prior to
    >> installing PyXML, I was previously calling parse() and Document().
    >>
    >> So did I make a mistake installing PyXML?

    >
    >This is uncertain. Does this also happen when you invoke Python from
    >the command line? If so, what happens if you do
    >
    >import xml
    >print xml
    >import xml.dom
    >print xml.dom
    >import xml.dom.minidom
    >print xml.dom.minidom
    >


    It turns out I made a bad choice naming my test program 'xml.py'. I
    discovered that these commands failed in the directory I was working
    on the script in, but succeeded elsewhere.

    I guess I didn't realise that my local files could interfere with
    importing from Pythons libraries. Stupid mistake on my part!

    Thanks again!

    Matt

    ---
    Systems Engineer, Hipbone(EMEA) Ltd.
    3000 Hillswood drive, Chertsey, Surrey, KT16 0RS
    Tel: 44-1932-895902 Mob: 44-7980-237-380
    Matt Mower, Jun 28, 2003
    #3
  4. Matt Mower <> writes:

    > Nothing in the environment or access to the file system suggests to me
    > why it works as for my account but not for the nobody account.


    So I'll ask my questions again: Print xml, xml.dom, xml.dom.minidom
    both in the interactive mode and the CGI script.

    Martin
    Martin v. =?iso-8859-15?q?L=F6wis?=, Jun 28, 2003
    #4
  5. Matt Mower

    Matt Mower Guest

    Hi Martin,

    On 28 Jun 2003 19:49:58 +0200, (Martin v. Löwis)
    wrote:

    >Matt Mower <> writes:
    >
    >> Nothing in the environment or access to the file system suggests to me
    >> why it works as for my account but not for the nobody account.

    >
    >So I'll ask my questions again: Print xml, xml.dom, xml.dom.minidom
    >both in the interactive mode and the CGI script.
    >


    Sorry, sometimes I don't listen so good.

    Interactively as user 'nobody':

    |>>> import xml
    |>>> print xml
    |<module 'xml' from '/opt/python/lib/python2.2/xml/__init__.pyc'>
    |>>> import xml.dom
    |>>> print xml.dom
    |<module 'xml.dom' from '/opt/python/lib/python2.2/xml/dom/__init__.pyc'>
    |>>> import xml.dom.minidom
    |>>> print xml.dom.minidom
    |<module 'xml.dom.minidom' from '/opt/python/lib/python2.2/xml/dom/minidom.pyc'>

    via CGI webserver running as user 'nobody':

    |<module 'xml' from '/opt/python/lib/python2.2/xml/__init__.pyc'>
    |<module 'xml.dom' from '/opt/python/lib/python2.2/xml/dom/__init__.pyc'>
    |<module 'xml.dom.minidom' from '/opt/python/lib/python2.2/xml/dom/minidom.pyc'>

    Regards,

    Matt

    ---
    Systems Engineer, Hipbone(EMEA) Ltd.
    3000 Hillswood drive, Chertsey, Surrey, KT16 0RS
    Tel: 44-1932-895902 Mob: 44-7980-237-380
    Matt Mower, Jun 28, 2003
    #5
  6. Matt Mower <> writes:

    > |>>> import xml
    > |>>> print xml
    > |<module 'xml' from '/opt/python/lib/python2.2/xml/__init__.pyc'>
    > |>>> import xml.dom
    > |>>> print xml.dom
    > |<module 'xml.dom' from '/opt/python/lib/python2.2/xml/dom/__init__.pyc'>
    > |>>> import xml.dom.minidom
    > |>>> print xml.dom.minidom
    > |<module 'xml.dom.minidom' from '/opt/python/lib/python2.2/xml/dom/minidom.pyc'>


    And you said you have PyXML installed? This sounds unlikely: minidom
    would come from site-packages/_xmlplus if you had.

    Regards,
    Martin
    Martin v. =?iso-8859-15?q?L=F6wis?=, Jun 28, 2003
    #6
  7. Matt Mower

    Andreas Jung Guest

    I think you should have installed a recent version of Expat.

    -aj

    --On Samstag, 28. Juni 2003 16:23 Uhr +0100 Matt Mower
    <> wrote:

    > Hi folks,
    >
    > I have an old Linux box that I am messing about with Python on. The
    > RedHat installed version is 1.5 something so I have built & installed
    > 2.2.2 in /opt/python.
    >
    > I've started trying to play with XML and ran into an error when
    > attempting to parse a document:
    >
    >> Traceback (most recent call last):
    >> File "/mnt/hugedisk/share/MattsMovableType/stb/stb.cgi", line 90, in ?
    >> documentElem = parse( rssFile )
    >> File "/opt/python/lib/python2.2/xml/dom/minidom.py", line 962, in parse
    >> return _doparse(pulldom.parse, args, kwargs)
    >> File "/opt/python/lib/python2.2/xml/dom/minidom.py", line 953, in
    >> _doparse events = apply(func, args, kwargs)
    >> File "/opt/python/lib/python2.2/xml/dom/pulldom.py", line 328, in parse
    >> parser = xml.sax.make_parser()
    >> File "/opt/python/lib/python2.2/xml/sax/__init__.py", line 93, in
    >> make_parser raise SAXReaderNotAvailable("No parsers found", None)
    >> xml.sax._exceptions.SAXReaderNotAvailable: No parsers found

    >
    > Googling around it seems like I needed to build XML support when I
    > built Python. I'm not sure what I should have done differently when I
    > built in order to make that happen. The other option on offer
    > appeared to be installing PyXML.
    >
    > I duly downloaded PyXML 0.8.2 and installed it (again into /opt/python
    > using --prefix).
    >
    > Now instead of the previous error I get a different problem entirely:
    >
    >> Traceback (most recent call last):
    >> File "/mnt/hugedisk/share/MattsMovableType/stb/stb.cgi", line 18, in ?
    >> from xml.dom.minidom import parse, Document
    >> File "./xml.py", line 2, in ?
    >> from xml.dom.minidom import parse
    >> ImportError: No module named dom.minidom

    >
    > I'm pretty sure I had a module dom.minidom before as it is the import
    > statement that is raising the exception and it didn't prior to
    > installing PyXML, I was previously calling parse() and Document().
    >
    > So did I make a mistake installing PyXML? Can anyone advise me on
    > what my next steps should be?
    >
    > Many thanks,
    >
    > Matt
    >
    > ---
    > Systems Engineer, Hipbone(EMEA) Ltd.
    > 3000 Hillswood drive, Chertsey, Surrey, KT16 0RS
    > Tel: 44-1932-895902 Mob: 44-7980-237-380
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    Andreas Jung, Jun 28, 2003
    #7
  8. Matt Mower

    Matt Mower Guest

    Hi Martin,

    On 28 Jun 2003 20:24:19 +0200, (Martin v. Löwis)
    wrote:

    >Matt Mower <> writes:
    >
    >> |>>> import xml
    >> |>>> print xml
    >> |<module 'xml' from '/opt/python/lib/python2.2/xml/__init__.pyc'>
    >> |>>> import xml.dom
    >> |>>> print xml.dom
    >> |<module 'xml.dom' from '/opt/python/lib/python2.2/xml/dom/__init__.pyc'>
    >> |>>> import xml.dom.minidom
    >> |>>> print xml.dom.minidom
    >> |<module 'xml.dom.minidom' from '/opt/python/lib/python2.2/xml/dom/minidom.pyc'>

    >
    >And you said you have PyXML installed? This sounds unlikely: minidom
    >would come from site-packages/_xmlplus if you had.
    >


    The installation instructions that came with my PyXML distro (0.8.2)
    said to execute:

    python setup.py build
    python setup.py install

    I made one small adjustment, specifying the --prefix=/opt/python
    option to put PyXML in the same directory as Python 2.2.

    My entire Python developing experience runs to about an afternoons
    worth so I have no idea why PyXML isn't working or isn't being found.

    Can you suggest anything?

    Thanks,

    Matt

    ---
    Systems Engineer, Hipbone(EMEA) Ltd.
    3000 Hillswood drive, Chertsey, Surrey, KT16 0RS
    Tel: 44-1932-895902 Mob: 44-7980-237-380
    Matt Mower, Jun 28, 2003
    #8
  9. Matt Mower

    Matt Mower Guest

    On Sat, 28 Jun 2003 21:40:12 +0200, Andreas Jung
    <> wrote:

    >I think you should have installed a recent version of Expat.
    >


    You and Martin were both correct. This was the essential step.

    |<module '_xmlplus' from '/opt/python/lib/python2.2/site-packages/_xmlplus/__init__.pyc'>
    |<module 'xml.dom' from '/opt/python/lib/python2.2/site-packages/_xmlplus/dom/__init__.pyc'>
    |<module 'xml.dom.minidom' from '/opt/python/lib/python2.2/site-packages/_xmlplus/dom/minidom.pyc'>

    Which is what I think Martin was expecting to see earlier.

    My thanks to you both.

    Regards,

    Matt
    Matt Mower, Jun 28, 2003
    #9
  10. Matt Mower wrote:

    > Looks like I spoke a little too soon.
    >
    > The minimal test script:
    >
    > from xml.dom.minidom import parse, Document
    > doc = parse( "...some file..." )
    > print doc
    >
    > works, spitting out a reference to a minidom instance.
    >
    > However the CGI script which is, in a roundabout way, doing exactly
    > the same thing still comes up with the error:


    Whenever there's a difference in behavior between a program in your
    shell and in CGI (or someone else's shell), it's almost certainly a
    difference in paths. You said that you installed some Python utilities
    into some nonstandard places (like /opt/python); that's likely what your
    problem is.

    --
    Erik Max Francis && && http://www.alcyone.com/max/
    __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
    / \ Every astronaut who goes up knows the risks he or she faces.
    \__/ Sally Ride
    Erik Max Francis, Jun 28, 2003
    #10
  11. Matt Mower wrote:

    > I made one small adjustment, specifying the --prefix=/opt/python
    > option to put PyXML in the same directory as Python 2.2.


    Well, that's your problem right there. Note the symptomology of what
    Martin von Loewis asked you to test -- it prints different things for
    your interactive usage and the CGI script.

    > My entire Python developing experience runs to about an afternoons
    > worth so I have no idea why PyXML isn't working or isn't being found.


    That's because the problem you're running into here is a difference in
    environment between you running the program in your interactive shell
    and Apache running it as nobody. It's a general Unix issue, not
    specific to Python.

    > Can you suggest anything?


    The problem is that you've installed PyXML in /opt/python, which is a
    nonstandard place -- though that isn't in and of itself wrong if you
    know what you're doing. You've obviously adjusted your interactive
    environment to look in /opt/python, since you're running the scripts
    without problems locally, but CGI scripts do not run in your
    environment, and so aren't seeing what you've installed in /opt/python,
    since that is a nonstandard place. For a quick remedy, add something
    like this:

    import sys
    sys.path.append('/opt/python')

    to the top of your script. A more permanent solution would involve
    adding it to /usr/local/lib/pythonX.Y/site.py.

    --
    Erik Max Francis && && http://www.alcyone.com/max/
    __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
    / \ Every astronaut who goes up knows the risks he or she faces.
    \__/ Sally Ride
    Erik Max Francis, Jun 28, 2003
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cory Davis
    Replies:
    7
    Views:
    832
    Cory Davis
    Jan 14, 2005
  2. Steven D'Aprano

    Why are "broken iterators" broken?

    Steven D'Aprano, Sep 21, 2008, in forum: Python
    Replies:
    8
    Views:
    636
  3. Cameron Simpson

    Re: Why are "broken iterators" broken?

    Cameron Simpson, Sep 22, 2008, in forum: Python
    Replies:
    0
    Views:
    570
    Cameron Simpson
    Sep 22, 2008
  4. Fredrik Lundh

    Re: Why are "broken iterators" broken?

    Fredrik Lundh, Sep 22, 2008, in forum: Python
    Replies:
    0
    Views:
    590
    Fredrik Lundh
    Sep 22, 2008
  5. John Ladasky
    Replies:
    3
    Views:
    1,145
    John Ladasky
    Jan 25, 2010
Loading...

Share This Page