Ubuntu下安装PyXerces遇编译错误及Python XQuery库缺失求助
Hey there, let's tackle your Python XQuery issues one by one:
That fatal error: dom/DOMAttr.h: No such file or directory is totally normal on Ubuntu—here's why and how to fix it:
PyXerces isn't a pure Python library; it's a wrapper around the Xerces-C++ XML parser. When you install it via pip, it tries to compile the C++ bindings from source, which requires the Xerces-C++ development headers and libraries to be present on your system. Ubuntu doesn't include these by default, hence the missing header error.
To fix this:
- First install the system-level Xerces-C++ development package:
sudo apt-get update && sudo apt-get install libxerces-c-dev - Once that's done, re-run your pip install command:
sudo pip install PyXerces
If you still hit compilation issues after this, it might be a version mismatch between PyXerces and the Xerces-C++ version provided by Ubuntu 18.04. In that case, you could try downloading the PyXerces source directly and compiling it with explicit paths to the Xerces headers/libraries, but the above step should work for most cases.
Since Zorba is no longer maintained and doesn't work on Ubuntu 18.04, here are three reliable alternatives that support XQuery:
lxml with XPath 2.0 (limited XQuery support)
If your XQuery needs are relatively simple (e.g., basic queries that overlap with XPath 2.0), lxml is a solid, well-maintained option. It's pre-packaged for Ubuntu:sudo apt-get install python3-lxmlWhile it doesn't support full XQuery, its XPath 2.0 implementation covers many common use cases, and it's far more lightweight than full XQuery processors.
Saxon-C (full XQuery 3.1 support)
Saxon is the industry standard for XQuery and XSLT processing. The Saxon-C edition provides a Python API that supports complete XQuery 3.1. To use it:- Install the Saxon-C deb package (you can grab it from the official Saxon releases page directly)
- Install the Python bindings via pip:
pip install saxonc
This is the best choice if you need full, compliant XQuery support.
BaseX (XQuery with XML database integration)
BaseX is an open-source XML database that includes a robust XQuery processor. It has a Python API that lets you execute XQuery queries against XML documents or the database. Install it with:sudo apt-get install basex pip install basexIt's great if you're working with large XML datasets or need database-backed XML processing.
内容的提问来源于stack exchange,提问作者Erhan

