0
votes

We use matlab's python engine to interface with matlab code from python. There seems to be some conflict with the used libexpact.so library.

A minimal buggy example would be:

#!/usr/bin/env python
from xml.dom import minidom
import matlab.engine

a = minidom.parse("solution_example.xml")
print(a)

This produces the output:

  File "./minimal.py", line 9, in <module>
    a = minidom.parse("solution_example.xml")   File "/usr/lib/python2.7/xml/dom/minidom.py", line 1917, in parse
    from xml.dom import expatbuilder   File "/usr/lib/python2.7/xml/dom/expatbuilder.py", line 32, in <module>
    from xml.parsers import expat   File "/usr/lib/python2.7/xml/parsers/expat.py", line 4, in <module>
    from pyexpat import * ImportError: /usr/lib/python2.7/lib-dynload/pyexpat.x86_64-linux-gnu.so: undefined symbol: XML_SetHashSalt

However, the program runs fine when the line import matlab.engine is omitted.

Any ideas what the problem could be or how we could debug the python import procedure?

Thanks in advance!

1
This has probably got something to do with LD_LIBRARY_PATH causing conflicts. Try unsetting that by doing setenv('LD_LIBRARY_PATH', '') and then calling your python code from MATLAB.Thomas Ibbotson
The variable LD_LIBRARY_PATH is already empty when we run the minimal example. We tried playing around with setting the appropriate matlab paths but the error persists. What do you mean with 'calling your python code from MATLAB'? Our code works the other way: we call matlab from python.dassmann
Sorry I misread your question, I thought you were calling your python code from within MATLAB. Not the other way around.Thomas Ibbotson

1 Answers

3
votes

I faced the same error message this morning and after looking around, I found this solution works for me. So I re-post here. Hope this help in future.

"It seems that this is caused by library conflicts with libexpat. I did ldd /usr/lib/python2.7/lib-dynload/pyexpat.so and realized that my libexpat.so.1 was pointing to /usr/local/lib/libexpat.so.1 rather than /lib/x86_64-linux-gnu/libexpat.so.1 (the former referencing an outdated version, 1.5.2 instead of 1.6.0). I don't know where the libexpat in /usr/local/lib came from.

I hide my libexpat files in /usr/local/lib (renamed with .backup appended) and now running ldd /usr/lib/python2.7/lib-dynload/pyexpat.so displays the line "libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1" and update-manager works correctly."

https://ubuntuforums.org/showthread.php?t=2094005