Matlab's python engine crashes minidom
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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!
0 comentarios
Respuestas (2)
Robert Snoeberger
el 8 de Feb. de 2016
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 comentarios
Mario Martos
el 11 de Mayo de 2016
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
el 21 de Mayo de 2018
Editada: Anshul Joshi
el 21 de Mayo de 2018
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).
0 comentarios
Ver también
Categorías
Más información sobre Call MATLAB from Python en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!