Have I broken my installation?

M

Matt Mower

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
 
M

Martin v. =?iso-8859-15?q?L=F6wis?=

Matt Mower said:
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:


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
 
M

Matt Mower

Hi Martin,

Thanks for responding. My answers are below.

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
 
M

Martin v. =?iso-8859-15?q?L=F6wis?=

Matt Mower said:
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
 
M

Matt Mower

Hi Martin,

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
 
M

Martin v. =?iso-8859-15?q?L=F6wis?=

Matt Mower said:
|>>> 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
 
A

Andreas Jung

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

-aj

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

Matt Mower

Hi Martin,

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
 
M

Matt Mower

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
 
E

Erik Max Francis

Matt said:
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.
 
E

Erik Max Francis

Matt said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top