import numpy to matlab

345 ビュー (過去 30 日間)
Ronald Kurnik
Ronald Kurnik 2018 年 7 月 15 日
回答済み: Paul Kuberry 2020 年 3 月 26 日
I have installed python 3.6 as well as spyder, numpy, pandas, scipy, and matplotlib from the Anaconda3(64 bit) distribution. I followed the MATLAB directions and call call simple python scrips in MATLAB. What I have not been able to do is to use any of the packages numpy, pandas, scipy, and matplotlib. The MATLAB command py.importlib.import_module('numpy') does not work.
Thanks in advance for your help.
  2 件のコメント
Stephen23
Stephen23 2018 年 7 月 15 日
"The MATLAB command py.importlib.import_module('numpy') does not work."
Please explain exactly what happens when you try it, including the complete error messages or warnings if you get any.
Stephen23
Stephen23 2018 年 7 月 15 日
Ronald Kurnik's "Answer" moved here:
This is my code saved as d6.py
py.importlib.import_module('numpy')
def fun2(x,z1,z2,z3,z4,z5):
y=z1+z2*x + z3/((1+numpy.exp(-z4*(x-z5))))
return y
pyversion
version: '3.6'
executable: 'C:\Users\Ron\Anaconda3\pkgs\python-3.6.5-h0c2934d_0\python.exe'
library: 'C:\Users\Ron\Anaconda3\pkgs\python-3.6.5-h0c2934d_0\python36.dll'
home: 'C:\Users\Ron\Anaconda3\pkgs\python-3.6.5-h0c2934d_0'
isloaded: 0
>> py.math.exp(1)
ans =
2.7183
>> d6 = py.importlib.import_module('d6');
Error using d6><module> (line 2)
Python Error: NameError: name 'py' is not defined
Error in <frozen importlib>_call_with_frames_removed (line 219)
Error in <frozen importlib>exec_module (line 678)
Error in <frozen importlib>_load_unlocked (line 665)
Error in <frozen importlib>_find_and_load_unlocked (line 955)
Error in <frozen importlib>_find_and_load (line 971)
Error in <frozen importlib>_gcd_import (line 994)
Error in __init__>import_module (line 126)
return _bootstrap._gcd_import(name[level:], package, level)

サインインしてコメントする。

回答 (3 件)

Tushar Agarwal
Tushar Agarwal 2019 年 9 月 26 日
Although Anaconda with MATLAB is not officially supported, you could access it using anaconda prompt. Please refer to this question https://www.mathworks.com/matlabcentral/answers/427187-problem-with-python-numpy for more details.
I am summarizing the straightforward approach that worked for me:
  1. Open Anaconda prompt (comes with the package). Optional: Activate any environments if you wish or just work with the default base environment.
  2. Change the directory to the one containing the matlab executable. Eg: "cd C:\Program Files\MATLAB\R2018b\bin"
  3. Run matlab by just running "matlab" command in the prompt.
  4. Verify using something like "py.help('numpy')" in the loaded matlab window.
Please Up-vote if it helps you. Thanks!

Saurabh Kelkar
Saurabh Kelkar 2019 年 7 月 12 日
I have same error. Can someone please help on this ?

Paul Kuberry
Paul Kuberry 2020 年 3 月 26 日
mkl_* libraries are not in a location where they can be loaded when calling Python from Matlab (unless Matlab is called using the Anaconda Prompt). This is why the issue appears for any Python package that relies on Numpy.

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by