Matlab's python engine crashes minidom

조회 수: 10 (최근 30일)
MSirvent
MSirvent 2016년 2월 8일
편집: Anshul Joshi 2018년 5월 21일
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!

답변 (2개)

Robert Snoeberger
Robert Snoeberger 2016년 2월 8일
matlab.engine uses libexpat.so shipped with MATLAB. It seems that the version shipped with MATLAB is an older version of the library, which is missing the symbol XML_SetHashSalt.
A possible workaround is to import pyexpat before matlab.engine. This will cause the system libexpat.so to be loaded instead of MATLAB’s libexpat.so.
Example
#!/usr/bin/env python
from xml.dom import minidom
import pyexpat # <-- import pyexpat before matlab.engine
import matlab.engine
a = minidom.parse("solution_example.xml")
print(a)
This workaround may cause MATLAB functions that depend on libexpat to break.
  댓글 수: 2
MSirvent
MSirvent 2016년 2월 11일
Thanks a lot! The workaround works perfectly well ...
Mario Martos
Mario Martos 2016년 5월 11일
Hello, Hello, I think I have the same problem , I'm using matlab 2015a in ubuntu 15.10 , but I've done what you have said and still get the error or problem .... Have you and idea of what can happen? Could you help me on this?
command = ['python xml2abc.py -p 0.83,1,21.0,1.00,1.00,1,1 ' song.filename]; >> [status,cmdout] = system(command); >> cmdout
cmdout =
type 'exceptions.ImportError'> occurred: No module named expat; use SimpleXMLTreeBuilder instead in Bach789Sco.xml
And when I put import pyexpat:
#!/usr/bin/env python # coding=latin-1 import pyexpat
try: import xml.etree.cElementTree as E except: import xml.etree.ElementTree as E
...etc
load('datosfile.mat'); >> command = ['python xml2abc.py -p 0.83,1,21.0,1.00,1.00,1,1 ' song.filename];
>> [status,cmdout] = system(command); >> cmdout
cmdout =
Traceback (most recent call last): File "xml2abc.py", line 16, in module import pyexpat ImportError: /usr/lib/python2.7/lib-dynload/pyexpat.x86_64-linux-gnu.so: undefined symbol: XML_SetHashSalt
py.sys.path
ans =
Python list with no properties.
['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client']
Thanks in advanced!

댓글을 달려면 로그인하십시오.


Anshul Joshi
Anshul Joshi 2018년 5월 21일
편집: Anshul Joshi 2018년 5월 21일
I was having similar problem. I switched my Python version from 3.6 to 2.7 and it worked, i.e. no more XML_SetHashSalt error. It's not a real fix, but I think the problem is that something breaks when you add/switch paths in your LD_LIBRARY_PATH or when Matlab introduces some libraries (e.g. in my case the "libpython3.6m.so.1.0: undefined symbol: XML_SetHashSalt" error).
I had also tried using the approach of importing pyexpat in Python but after importing I started getting Segmentation Faults (when I was using Python 3.6).

카테고리

Help CenterFile Exchange에서 Call MATLAB from Python에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by