title: Matlab-Python compiler SDK fails with "undefined symbol: XML_SetHashSalt"
body: <p>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).</p>
  
  <p>I have a Matlab code which am trying to call from Python by using and following the instructions on the <a href="https://www.mathworks.com/help/compiler_sdk/gs/create-a-python-application-with-matlab-code.html" rel="nofollow noreferrer">Matlab Compiler SDK for Python</a>. 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:</p>
  
  <pre><code>&lt;username&gt;:~/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.
  
  &gt;&gt;&gt; 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 "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "&lt;$HOME&gt;/MatlabWorkspace/rs_cuboid_measure_script_python_attempt2/for_testing/rs_cuboid_measure_script_python/__init__.py", line 283, in &lt;module&gt;
  _pir.import_cppext()
  File "&lt;$HOME&gt;/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
  </code></pre>
  
  <p>Here the rs_cuboid_measure_script_python is my Matlab module that works perfectly when run in Matlab.</p>
  
  <p>I have looked at the following relevant answers on various forums:</p>
  
  <p>1) <a href="https://www.mathworks.com/matlabcentral/answers/267099-matlab-s-python-engine-crashes-minidom" rel="nofollow noreferrer">https://www.mathworks.com/matlabcentral/answers/267099-matlab-s-python-engine-crashes-minidom</a> (most relevant)</p>
  
  <p>If I follow the advice on this link and </p>
  
  <pre><code> import pyexpat 
  </code></pre>
  
  <p>before importing my module, I get a segfault:</p>
  
  <pre><code>&gt;&gt;&gt; import pyexpat
  &gt;&gt;&gt; import rs_cuboid_measure_script_python
  Segmentation fault (core dumped)
  </code></pre>
  
  <p>2) <a href="https://stackoverflow.com/questions/35266973/python-application-crash-with-error-importerror-pyexpat-x86-64-linux-gnu-so-u">Python application crash with error &quot;ImportError: pyexpat.x86_64-linux-gnu.so: undefined symbol: XML_SetHashSalt&quot;</a></p>
  
  <p>Based on this link, the dependencies are:</p>
  
  <pre><code>&lt;username&gt;:/usr/lib/x86_64-linux-gnu$ ldd libpython3.6m.so.1.0
  
  linux-vdso.so.1 =&gt;  (0x00007ffed491a000)
  libexpat.so.1 =&gt; /usr/local/MATLAB/MATLAB_Runtime/v94/bin/glnxa64/libexpat.so.1 (0x00007f90cb2b4000)
  libz.so.1 =&gt; /lib/x86_64-linux-gnu/libz.so.1 (0x00007f90cb09a000)
  libpthread.so.0 =&gt; /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f90cae7d000)
  libdl.so.2 =&gt; /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f90cac79000)
  libutil.so.1 =&gt; /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f90caa76000)
  libm.so.6 =&gt; /lib/x86_64-linux-gnu/libm.so.6 (0x00007f90ca76d000)
  libc.so.6 =&gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007f90ca3a3000)
  /lib64/ld-linux-x86-64.so.2 (0x00007f90cbbd1000)
  </code></pre>
  
  <p>3) Based on Mathworks support's suggestion, I resinstalled python by following instructions on this <a href="https://askubuntu.com/questions/187227/i-run-sudo-apt-get-remove-python2-7-can-i-restore-my-ubuntu-now">link</a> but that didn't change anything. I get the same error as above</p>
  
  <p>Some other links that may or may not be relevant:</p>
  
  <p>4) <a href="https://askubuntu.com/questions/601106/trying-to-run-hp-toolbox-from-hplip-but-gives-python-errors/601178#601178">https://askubuntu.com/questions/601106/trying-to-run-hp-toolbox-from-hplip-but-gives-python-errors/601178#601178</a></p>
  
  <p>5) <a href="https://github.com/sqlmapproject/sqlmap/issues/2194" rel="nofollow noreferrer">https://github.com/sqlmapproject/sqlmap/issues/2194</a>
  Note: I have changed my LD_LIBRARY_PATH variable to:</p>
  
  <pre><code>:~$ 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/
  </code></pre>
  
  <p>based on instructions given on <a href="https://www.mathworks.com/help/compiler_sdk/python/install-a-matlab-compiler-sdk-python-package.html" rel="nofollow noreferrer">Matlab compiler SDK website</a>
  (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).</p>
  
  <p>6) <a href="https://github.com/opencv/opencv/issues/5445" rel="nofollow noreferrer">https://github.com/opencv/opencv/issues/5445</a></p>
  
  <pre><code>:/usr/lib/x86_64-linux-gnu$ strings libpython3.6m.so.1.0 | grep Salt
  XML_SetHashSalt
  </code></pre>
  
  <p>Any help in tackling this problem is appreciated.</p>
  
  <p>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</p>
  
  <pre><code>:~/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.
  &gt;&gt;&gt; import rs_cuboid_measure_script_python
  &gt;&gt;&gt; rs = rs_cuboid_measure_script_python.initialize()
  &gt;&gt;&gt; rs.rs_cuboid_measure_script_python()
  Not enough input arguments. *this is OK this means my function is getting called*
  </code></pre>