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

조회 수: 10 (최근 30일)
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?

채택된 답변

Rubem Pacelli
Rubem Pacelli 2020년 3월 18일
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
Pierre Loicq
Pierre Loicq 2021년 4월 7일
I resolved the exact same problem on Matlab 2016b with this one : https://fr.mathworks.com/matlabcentral/answers/358233-matlab-python-interface-broken

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Hiro Yoshino
Hiro Yoshino 2020년 2월 4일
  댓글 수: 6
Rubem Pacelli
Rubem Pacelli 2020년 2월 5일
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 :(

댓글을 달려면 로그인하십시오.


Hiro Yoshino
Hiro Yoshino 2020년 2월 5일
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 2020년 2월 6일
Have you ever tried this ? - calling MATLAB from the anaconda prompt?

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by