Skip to content

Commit ed6638e

Browse files
committed
Add docs for troubleshooting the libxml2 mismatch issue
1 parent 3e10ad9 commit ed6638e

2 files changed

Lines changed: 106 additions & 0 deletions

File tree

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,58 @@ apk add build-base openssl libffi-dev openssl-dev libxslt-dev libxml2-dev xmlsec
8787

8888
## Troubleshooting
8989

90+
### `lxml & xmlsec libxml2 library version mismatch`
91+
92+
`xmlsec` passes `lxml` XML nodes to the underlying `xmlsec1` library. Both
93+
libraries use `libxml2`, so they must use compatible `libxml2` versions at
94+
runtime. If `lxml` is installed from a wheel that bundles one `libxml2`
95+
version while `xmlsec` is built against another system `libxml2`, importing
96+
or using `xmlsec` can fail with:
97+
98+
``` text
99+
xmlsec.InternalError: (-1, 'lxml & xmlsec libxml2 library version mismatch')
100+
```
101+
102+
The most reliable fixes are:
103+
104+
- Use prebuilt wheels for both `lxml` and `xmlsec` when wheels are available
105+
for your platform:
106+
107+
``` bash
108+
pip install --only-binary=lxml,xmlsec lxml xmlsec
109+
```
110+
111+
- If you need to build from source, build both packages against the same
112+
locally installed `libxml2`:
113+
114+
``` bash
115+
pip install --no-binary=lxml,xmlsec lxml xmlsec
116+
```
117+
118+
Do not mix a wheel-built `lxml` with a locally built `xmlsec`, or the other
119+
way around, unless you know they use the same `libxml2` version.
120+
121+
An `lxml` release upgrade does not by itself mean `xmlsec` is incompatible;
122+
this error is about the `libxml2` libraries loaded in that environment.
123+
124+
If the error appears only under uWSGI, uWSGI may have loaded the system
125+
`libxml2` before Python imports `lxml` or `xmlsec`. In that case, make sure
126+
uWSGI and the Python packages resolve to the same `libxml2`, or rebuild the
127+
Python packages from source in that environment. If you use `uv`, clear any
128+
cached mixed builds before reinstalling. For example, to reinstall from
129+
wheels:
130+
131+
``` bash
132+
uv pip uninstall lxml xmlsec
133+
uv cache clean
134+
uv pip install --only-binary lxml --only-binary xmlsec lxml xmlsec
135+
```
136+
137+
For background, see
138+
[issue #356](https://github.com/xmlsec/python-xmlsec/issues/356) and the
139+
uWSGI edge case in
140+
[issue #415](https://github.com/xmlsec/python-xmlsec/issues/415).
141+
90142
### Mac
91143

92144
If you get any fatal errors about missing `.h` files, update your

doc/source/install.rst

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,60 @@ Alpine
6565
Troubleshooting
6666
***************
6767

68+
``lxml & xmlsec libxml2 library version mismatch``
69+
--------------------------------------------------
70+
71+
``xmlsec`` passes ``lxml`` XML nodes to the underlying ``xmlsec1``
72+
library. Both libraries use ``libxml2``, so they must use compatible
73+
``libxml2`` versions at runtime. If ``lxml`` is installed from a wheel
74+
that bundles one ``libxml2`` version while ``xmlsec`` is built against
75+
another system ``libxml2``, importing or using ``xmlsec`` can fail with:
76+
77+
.. code-block:: text
78+
79+
xmlsec.InternalError: (-1, 'lxml & xmlsec libxml2 library version mismatch')
80+
81+
The most reliable fixes are:
82+
83+
* Use prebuilt wheels for both ``lxml`` and ``xmlsec`` when wheels are
84+
available for your platform:
85+
86+
.. code-block:: bash
87+
88+
pip install --only-binary=lxml,xmlsec lxml xmlsec
89+
90+
* If you need to build from source, build both packages against the same
91+
locally installed ``libxml2``:
92+
93+
.. code-block:: bash
94+
95+
pip install --no-binary=lxml,xmlsec lxml xmlsec
96+
97+
Do not mix a wheel-built ``lxml`` with a locally built ``xmlsec``, or the
98+
other way around, unless you know they use the same ``libxml2`` version.
99+
100+
An ``lxml`` release upgrade does not by itself mean ``xmlsec`` is
101+
incompatible; this error is about the ``libxml2`` libraries loaded in
102+
that environment.
103+
104+
If the error appears only under uWSGI, uWSGI may have loaded the system
105+
``libxml2`` before Python imports ``lxml`` or ``xmlsec``. In that case,
106+
make sure uWSGI and the Python packages resolve to the same ``libxml2``,
107+
or rebuild the Python packages from source in that environment. If you
108+
use ``uv``, clear any cached mixed builds before reinstalling. For
109+
example, to reinstall from wheels:
110+
111+
.. code-block:: bash
112+
113+
uv pip uninstall lxml xmlsec
114+
uv cache clean
115+
uv pip install --only-binary lxml --only-binary xmlsec lxml xmlsec
116+
117+
For background, see `issue #356 <https://github.com/xmlsec/python-xmlsec/issues/356>`_
118+
and the uWSGI edge case in
119+
`issue #415 <https://github.com/xmlsec/python-xmlsec/issues/415>`_.
120+
121+
68122
Mac
69123
---
70124

0 commit comments

Comments
 (0)