フィルターのクリア

Matlab's python engine crashes minidom

5 ビュー (過去 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 Center および File ExchangeCall MATLAB from Python についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by