在Matlab

时间:2018-02-22 15:50:11

标签: python matlab fedora

我在Matlab中使用操作系统命令来启动python脚本。所有这些工作都很好,直到最近,事实上我怀疑最近将Matlab升级到R2017b和Fedora升级到FC27。

事实:如果我在shell中启动脚本python,一切正常。但是如果我在Matlab中启动相同的脚本,则会引发一些ImportError异常:

Traceback (most recent call last):

  File "/usr/lib64/python3.6/xml/etree/ElementTree.py", line 1448, in __init__

    from xml.parsers import expat

  File "/usr/lib64/python3.6/xml/parsers/expat.py", line 4, in <module>

    from pyexpat import *

ImportError: /usr/lib64/python3.6/lib-dynload/pyexpat.cpython-36m-x86_64-linux-gnu.so: undefined symbol: XML_SetHashSalt



During handling of the above exception, another exception occurred:



Traceback (most recent call last):

  File "/usr/lib64/python3.6/xml/etree/ElementTree.py", line 1451, in __init__

    import pyexpat as expat

ImportError: /usr/lib64/python3.6/lib-dynload/pyexpat.cpython-36m-x86_64-linux-gnu.so: undefined symbol: XML_SetHashSalt



During handling of the above exception, another exception occurred:



Traceback (most recent call last):

  File "/data_1/IRM/amigo/src/IRMAGE_python_scripts/IRMAGE_report.py", line 1409, in <module>

    outFormat = 'png')

  File "/data_1/IRM/amigo/src/IRMAGE_python_modules/IRMAGE_reporting.py", line 1576, in plotPatVsRef

    bookRef = xlrd.open_workbook(refFile)

  File "/usr/lib/python3.6/site-packages/xlrd/__init__.py", line 422, in open_workbook

    ragged_rows=ragged_rows,

  File "/usr/lib/python3.6/site-packages/xlrd/xlsx.py", line 784, in open_workbook_2007_xml

    ensure_elementtree_imported(verbosity, logfile)

  File "/usr/lib/python3.6/site-packages/xlrd/xlsx.py", line 48, in ensure_elementtree_imported

    ET.iterparse(_dummy_stream)

  File "/usr/lib64/python3.6/xml/etree/ElementTree.py", line 1217, in iterparse

    pullparser = XMLPullParser(events=events, _parser=parser)

  File "/usr/lib64/python3.6/xml/etree/ElementTree.py", line 1256, in __init__

    self._parser = _parser or XMLParser(target=TreeBuilder())

  File "/usr/lib64/python3.6/xml/etree/ElementTree.py", line 1454, in __init__

    "No module named expat; use SimpleXMLTreeBuilder instead"

ImportError: No module named expat; use SimpleXMLTreeBuilder instead

我从昨天起就面临这个问题有点迷失了,我承认我没有新想法来解决这个问题......所有的想法,信息,对这个问题的帮助将非常受欢迎

1 个答案:

答案 0 :(得分:0)

我只是想知道有关引发ImportError异常的/usr/lib64/python3.6/lib-dynload/pyexpat.cpython-36m-x86_64-linux-gnu.so的共享对象依赖项!

在shell中:

% ldd /usr/lib64/python3.6/lib-dynload/pyexpat.cpython-36m-x86_64-linux-gnu.so
    linux-vdso.so.1 (0x00007ffd8f7c5000)
    libexpat.so.1 => /lib64/libexpat.so.1 (0x00007ff82fae8000)
    libpython3.6m.so.1.0 => /lib64/libpython3.6m.so.1.0 (0x00007ff82f588000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007ff82f369000)
    libc.so.6 => /lib64/libc.so.6 (0x00007ff82ef86000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007ff82ed82000)
    libutil.so.1 => /lib64/libutil.so.1 (0x00007ff82eb7f000)
    libm.so.6 => /lib64/libm.so.6 (0x00007ff82e82a000)
    /lib64/ld-linux-x86-64.so.2 (0x00007ff82ff2c000)

在Matlab中:

! ldd /usr/lib64/python3.6/lib-dynload/pyexpat.cpython-36m-x86_64-linux-gnu.so
        linux-vdso.so.1 (0x00007ffeec596000)
        libexpat.so.1 => /usr/local/MATLAB/R2017b/bin/glnxa64/libexpat.so.1 (0x00007fcd2931e000)
        libpython3.6m.so.1.0 => /lib64/libpython3.6m.so.1.0 (0x00007fcd28dbe000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fcd28b9f000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fcd287bc000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007fcd285b8000)
        libutil.so.1 => /lib64/libutil.so.1 (0x00007fcd283b5000)
        libm.so.6 => /lib64/libm.so.6 (0x00007fcd28060000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fcd29758000)

因此很明显,问题来自于Matlab distrib(libexpat.so.1.5.0)中较旧的libexpat.so.1共享对象,而不是系统(libexpat.so.1.6)。 7)!!!:

% ls -l /usr/local/MATLAB/R2017b/bin/glnxa64/libexpat.so*
lrwxrwxrwx. 1 root root     17 Feb 22 12:41 libexpat.so.1 -> libexpat.so.1.5.0
-r-xr-xr-x. 1 root root 182222 Jul 24  2017 libexpat.so.1.5.0
% ls -l /usr/lib64/libexpat.so*
lrwxrwxrwx. 1 root root     17 Nov  6 18:00 /usr/lib64/libexpat.so -> l    ibexpat.so.1.6.7
lrwxrwxrwx. 1 root root     17 Nov  6 18:00 /usr/lib64/libexpat.so.1 -> libexpat.so.1.6.7
-rwxr-xr-x. 1 root root 206000 Nov  6 18:00 /usr/lib64/libexpat.so.1.6.7

我通过将一个排除目录移动到Matlab distrib的共享对象来解决问题,强制使用系统中的一个!!!

# cd /usr/local/MATLAB/R2017b/bin/glnxa64
# mkdir exclude
# mv libexpat.so* exclude/

现在一切正常!

P.S。在Matlab和Fedora升级之后,我在Matlab上正确运行时遇到了一些其他问题,我在这里没有详细说明。但是如果有人在使用Matlab和FC26或FC27时遇到其他问题,我可以根据要求提供我所做的所有更改(所有这些都是关于Matlab发行版中太旧的共享对象!!!)