[Python-Dev] Python XML Validator

Ned Deily nad at acm.org
Wed Mar 5 00:44:32 CET 2008

In article <20080302230708.260fa4a9 at bhuda.mired.org>,
 Mike Meyer <mwm at mired.org> wrote:
> On Thu, 28 Feb 2008 23:42:49 +0000 (UTC) Medhat Gayed 
> <medhat.gayed at gmail.com> wrote:
> > lxml is good but not written in python and difficult to install and didn't 
> > work
> > on MacOS X.
> lxml is built on top of libxml2/libxslt, which are bundled with most
> Unix-like OS's (including Mac OS X), or available in their package
> systems. Trying to install it from the repository is a PITA, because
> it uses both the easyinstall and Pyrex (later Cython) packages - which
> aren't bundled with anything. On the other hand, if it's in the
> package system (I no longer have macports installed anywhere, but
> believe it was there at one time), that solves all those problems. I
> believe they've excised the easyinstall source dependencies, though.
> If you just want an xml module in the standard library that's more
> complete, I'd vote for the source distribution of lxml, as that's C +
> Python and built on top of commonly available libraries. The real
> issue would be making current lxml work with the "outdated" versions
> of those libraries found in current OS distributions.

I'm not sure what you perceive to be the problems with easy_install on 
OSX; I find it makes life *much* simpler for managing python packages.

Be that as it may, since the release of lxml 2.0, the project has 
updated the lxml website with useful information about source 
installations and, in particular, OSX source installations:


IIRC, here's what worked for me on Leopard (10.5.2) using the python.org 
2.5.2, though it should work fine with the Apple-supplied 2.5.1:

1. Download and build source tarballs of recent libxml2 (at the moment 
2.6.31 is the latest, OSX 10.5.2 has 2.6.16) and libxlst (1.1.22 vs 
1.1.12) from xmlsoft.org and then install them to /usr/local/.  (Don't 
bother with the python bindings unless they're needed for some other 

2. As noted on the lxml source page, Cython is not needed to install 
lxml and can complicate matters so, as suggested, if you have Cython (or 
Pyrex, for that matter) installed in the Python path you're going to 
install to, temporarily remove it(/them).

3. Using the lxml 2.0.x source tarball:
  /path/to/python setup.py install \

4. Verify installation:

$ which python
$ python
Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53) 
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from lxml import etree
>>> print etree.LXML_VERSION
(2, 0, 2, 0)
>>> print etree.LIBXML_VERSION
(2, 6, 31)
(2, 6, 31)
>>> print etree.LIBXSLT_VERSION
(1, 1, 22)
(1, 1, 22)

Clearly there are other ways to do this but HTH.

 Ned Deily,
 nad at acm.org

More information about the Python-Dev mailing list