Python 3.4 : How to do xml validation
Question: I'm trying to do XML validation against some XSD in python. I was successful
using lxml package. But the problem starts when I tried to port my code into
python 3.4. I tried to install lxml for 3.4 version. Looks like my enterprise
linux doesn't play very well with lxml.

**pip installation:**

    
    
    pip install lxml
    Collecting lxml
      Downloading lxml-3.4.4.tar.gz (3.5MB)
        100% |################################| 3.5MB 92kB/s
    Installing collected packages: lxml
      Running setup.py install for lxml
    Successfully installed lxml-3.4.4
    

**After pip Installation :**

    
    
    > python
    Python 3.4.1 (default, Nov 12 2014, 13:34:29)
    [GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from lxml import etree
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ImportError: /ws/satjonna-sjc/pyats/lib/python3.4/site-packages/lxml/etree.cpython-34m.so: undefined symbol: xmlMemDisplayLast
    >>>
    

**git installation:**

    
    
    git clone git://github.com/lxml/lxml.git lxml
    Cloning into 'lxml'...
    remote: Counting objects: 25078, done.
    remote: Total 25078 (delta 0), reused 0 (delta 0), pack-reused 25078
    Receiving objects: 100% (25078/25078), 21.38 MiB | 2.66 MiB/s, done.
    Resolving deltas: 100% (9854/9854), done.
    Checking connectivity... done.
    

**After git Installation :**

    
    
    > python
    Python 3.4.1 (default, Nov 12 2014, 13:34:29)
    [GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from lxml import etree
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ImportError: cannot import name 'etree'
    

I found lxml equivalent
[xml.etree.ElementTree](https://docs.python.org/3.4/library/xml.etree.elementtree.html).
But the main problem is apart from rewriting the entire code, I need to find
an xml.etree alternative for lxml validation moethod (
**_etree.fromstring(xmlstring, xmlparser)_** ). Any suggestions to make this
work will be really helpful.


Answer: Just for the sake of troubleshooting, did you run `pip install lxml` as
administrator? And are the libxml2 and libxslt dependencies installed?

This is from the installation page: <http://lxml.de/installation.html>

On Linux (and most other well-behaved operating systems), pip will manage to
build the source distribution as long as libxml2 and libxslt are properly
installed, including development packages, i.e. header files, etc. See the
requirements section above and use your system package management tool to look
for packages like libxml2-dev or libxslt-devel. If the build fails, make sure
they are installed. Alternatively, setting STATIC_DEPS=true will download and
build both libraries automatically in their latest version, e.g.
STATIC_DEPS=true pip install lxml.

