Python 3.4 : How to do xml validation
Asked Answered
C

1

2

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. 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.

Cully answered 7/7, 2015 at 15:48 Comment(1)
for lxml do you have both libxml2 and libxslt? try: yum install libxml2-devel libxslt-devel , and install lxml againHobbie
S
0

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.

Shagreen answered 7/7, 2015 at 16:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.