4
votes

I am working on Ubuntu 16.04 64-bit with Matlab R2018a and using Python 3.6 (and 3.5 and 2.7 installed but not using).

I have a Matlab code which am trying to call from Python by using and following the instructions on the Matlab Compiler SDK for Python. I follow all the instructions on this link to the word, I create my Matlab-Python wrapper (web) installers and install them, I change the LD_LIBRARY_PATH as suggested by the installer. I have tried the MagicSquarePkg example that they have shown and it was working well with this approach. However the MagicSquarePkg did not use any Matlab toolbox functions; my code does. After I follow this procedure with my code I get the following error:

<username>:~/MatlabWorkspace/rs_cuboid_measure_script_python_attempt2/for_testing$ python3.6

Python 3.6.5 (default, Mar 29 2018, 03:28:50) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.

>>> import rs_cuboid_measure_script_python *my Matlab module*
Exception caught during initialization of Python interface. Details: 
/usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0: undefined symbol: 
XML_SetHashSalt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<$HOME>/MatlabWorkspace/rs_cuboid_measure_script_python_attempt2/for_testing/rs_cuboid_measure_script_python/__init__.py", line 283, in <module>
_pir.import_cppext()
File "<$HOME>/MatlabWorkspace/rs_cuboid_measure_script_python_attempt2/for_testing/rs_cuboid_measure_script_python/__init__.py", line 276, in import_cppext
self.cppext_handle = importlib.import_module("matlabruntimeforpython" + self.interpreter_version)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0: undefined symbol: XML_SetHashSalt

Here the rs_cuboid_measure_script_python is my Matlab module that works perfectly when run in Matlab.

I have looked at the following relevant answers on various forums:

1) https://www.mathworks.com/matlabcentral/answers/267099-matlab-s-python-engine-crashes-minidom (most relevant)

If I follow the advice on this link and

 import pyexpat 

before importing my module, I get a segfault:

>>> import pyexpat
>>> import rs_cuboid_measure_script_python
Segmentation fault (core dumped)

2) Python application crash with error "ImportError: pyexpat.x86_64-linux-gnu.so: undefined symbol: XML_SetHashSalt"

Based on this link, the dependencies are:

<username>:/usr/lib/x86_64-linux-gnu$ ldd libpython3.6m.so.1.0

linux-vdso.so.1 =>  (0x00007ffed491a000)
libexpat.so.1 => /usr/local/MATLAB/MATLAB_Runtime/v94/bin/glnxa64/libexpat.so.1 (0x00007f90cb2b4000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f90cb09a000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f90cae7d000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f90cac79000)
libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f90caa76000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f90ca76d000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f90ca3a3000)
/lib64/ld-linux-x86-64.so.2 (0x00007f90cbbd1000)

3) Based on Mathworks support's suggestion, I resinstalled python by following instructions on this link but that didn't change anything. I get the same error as above

Some other links that may or may not be relevant:

4) https://askubuntu.com/questions/601106/trying-to-run-hp-toolbox-from-hplip-but-gives-python-errors/601178#601178

5) https://github.com/sqlmapproject/sqlmap/issues/2194 Note: I have changed my LD_LIBRARY_PATH variable to:

:~$ echo $LD_LIBRARY_PATH 
:/usr/local/MATLAB/MATLAB_Runtime/v94/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v94/bin/glnxa64/:/usr/local/MATLAB/MATLAB_Runtime/v94/sys/os/glnxa64/

based on instructions given on Matlab compiler SDK website (note: the correct paths are not exactly the ones on the link but the ones on the console output above as confirmed my Mathworks support).

6) https://github.com/opencv/opencv/issues/5445

:/usr/lib/x86_64-linux-gnu$ strings libpython3.6m.so.1.0 | grep Salt
XML_SetHashSalt

Any help in tackling this problem is appreciated.

EDIT: On a hunch, I ran my Matlab module with Python2.7 instead of 3.6 and it seems to be working with 2.7 but not with 3.6

:~/MatlabWorkspace/rs_cuboid_measure_script_python_attempt2/for_testing$ python2.7
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import rs_cuboid_measure_script_python
>>> rs = rs_cuboid_measure_script_python.initialize()
>>> rs.rs_cuboid_measure_script_python()
Not enough input arguments. *this is OK this means my function is getting called*
3

3 Answers

10
votes

I'm having the same issue. Solved:

cd /full_path_to_matlab_mcrroot/v94/bin/glnxa64
mv libexpat.so.1 libexpat.so.1.NOFIND

Thanks to https://bbs.archlinux.org/viewtopic.php?pid=1112017#p1112017

  • Explanation:

/full_path_to_matlab_mcrroot/v94/bin/glnxa64/libexpat.so.1 pointed to libexpat.so.1.5.0

but

/lib/x86_64-linux-gnu/libexpat.so.1 pointed to libexpat.so.1.6.0

1
votes

I'm having this exact problem. Same error. Using Python 2.7 instead of Python 3.5 also worked for me. Thanks.

However I would really like to know how to make it work on 3.6 as I intend on using the Matlab program on a Django server running on 3.6.

0
votes

export LD_LIBRARY_PATH=/lib64/:$LD_LIBRARY_PATH