Why matlab crashes when I try to use a numpy Python package? (2019a)

11 views (last 30 days)
I'm trying to use Python on Matlab, but the system crashes everytime I try to use a Numpy Package.
My only step was to switch the pyversion to match with anaconda executable version (I'm on Linux):
pyversion
version: '3.7'
executable: '/home/rubem/anaconda3/bin/python'
library: '/home/rubem/anaconda3/lib/libpython3.7m.so'
home: '/home/rubem/anaconda3'
isloaded: 0
If a type something like:
py.importlib.import_module('numpy')
or:
py.numpy.limspace(0,10,101)
Matlab crashes. In the Terminal, the following command appear:
malloc(): memory corruption
/usr/local/bin/matlab: line 3: 1874 Segmentation fault sudo /usr/local/Polyspace/R2019a/bin/matlab
Despite the lack of documentation on Matlab, I tried to find out what the hell was going on and I found out two interesting things:
1 - I followed the example in https://www.mathworks.com/help/matlab/matlab_external/call-user-defined-custom-module.html and it's works. So I Think that just the numpy package has the problem
2 - If I type
py.sys.path
I recieve:
ans =
Python list with no properties.
['', '/home/rubem/anaconda3/lib/python37.zip', '/home/rubem/anaconda3/lib/python3.7', '/home/rubem/anaconda3/lib/python3.7/lib-dynload', '/home/rubem/anaconda3/lib/python3.7/site-packages']
That's weird because the second one isn't a path folder (python37 is a .zip-file that doesn't exist). Unfortunately, I don't know how I can change this.
3 - "isloaded" is equal to zero when the matlab initialize. I don't know neither how I set this logical variable nor what is this does (I swear for god I searched, but the documentation on Matlab is very poor yet).
How can I solve this problem?

Accepted Answer

Rubem Pacelli
Rubem Pacelli on 18 Mar 2020
I think the problem was my program. I switched to 2018b and it seems to work.
btw, I think its more useful to close this post because the problem wasn't technical questions.
  1 Comment
Pierre Loicq
Pierre Loicq on 7 Apr 2021
I resolved the exact same problem on Matlab 2016b with this one : https://fr.mathworks.com/matlabcentral/answers/358233-matlab-python-interface-broken

Sign in to comment.

More Answers (3)

Hiro Yoshino
Hiro Yoshino on 4 Feb 2020
  6 Comments
Rubem Pacelli
Rubem Pacelli on 5 Feb 2020
Hiro Yoshino, i saw all yours links.
1 - The command "pyenv" seems don't exist on 2019a.
Undefined function or variable 'pyenv'
2 - According to what I read: "MATLAB automatically selects and loads a Python version when you type a Python command, such as: py.funcname" . I did it. I created a silly .py-function called "my_python_function.py" and I call it from matlab. It's work because I don't use numpy package. Then, I typed pyversion and I recieve:
version: '3.7'
executable: '/home/rubem/anaconda3/bin/python'
library: '/home/rubem/anaconda3/lib/libpython3.7m.so'
home: '/home/rubem/anaconda3'
isloaded: 1
however, If I type then
py.importlib.import_module('numpy')
My matlab crashes anyway :(

Sign in to comment.


Hiro Yoshino
Hiro Yoshino on 5 Feb 2020
Read the documentation for R2019a. You might have counted on the latest. It might be a cause of the problem.
Sometimes, there exists slight difference across the versions.
https://jp.mathworks.com/help/releases/R2019a/index_ja_JP.html

Hiro Yoshino
Hiro Yoshino on 6 Feb 2020
Have you ever tried this ? - calling MATLAB from the anaconda prompt?

Community Treasure Hunt

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

Start Hunting!