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

8 次查看(过去 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