matlabでpyt​honモジュール(s​olve_ivp)を​実行できない。

24 views (last 30 days)
Yusuke Sakamaki
Yusuke Sakamaki on 20 Apr 2022
Edited: Yusuke Sakamaki on 21 Apr 2022
matlabでpythonモジュールを実行できず、エラーでmatlabが強制終了しました。
エラーを安全に回避する方法はありますか?
【実行環境】
・Windows 10
・MATLAB R2021a update 6(最新アップデート)
・Python 3.8.13 (Scipy 1.7.3をインストール)
matlabワークスペース上で以下を実行
py.test_func.hal
【python側】ファイル名:test_func.py
from scipy.integrate import solve_ivp
import numpy as np
def hal():
p_0 = 1.0; q_0 = 0.0
ini = [p_0,q_0]
tsp = [0.0,10.0]
tev = np.linspace(*tsp,100)
def halmc(t,x):
p,q = x
return [-q,p]
solv = solve_ivp(halmc,tsp,ini,method='RK45',t_eval=tev) #ここで強制終了
print(solv)
【エラー文】
MP: Error #15: Initializing libomp.dll, but found libiomp5md.dll already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://openmp.llvm.org/

Accepted Answer

Kojiro Saito
Kojiro Saito on 21 Apr 2022
MATLAB R2021a Update6、Python 3.8.10、Scipy 1.7.3及び1.8.0で試しましたが私の環境では再現しませんでした。
Stack overflowに同様のエラーが報告されていて、os.environ['KMP_DUPLICATE_LIB_OK']='True'を付ければ回避可能とのことです。
Python コードの冒頭に追記してみたらPython エラーは回避できそうです。
from scipy.integrate import solve_ivp
import numpy as np
import os
os.environ['KMP_DUPLICATE_LIB_OK']='True'
また、Python のエラーでMATLAB がこけないようにするために、try/catchでくくってみたらいかがでしょうか。
try
py.test_func.hal
catch ME
disp(ME)
end
  1 Comment
Yusuke Sakamaki
Yusuke Sakamaki on 21 Apr 2022
Edited: Yusuke Sakamaki on 21 Apr 2022
同じ環境で確認し、ご回答いただきありがとうございます。
エラーが再現しなかったとのことと、Stack overflowの内容から、
私の環境もAnaconda環境を利用しており、Anacondaを利用せずに同じ操作を実施したところ、
エラーが解消されました。
ご回答頂かなければ気が付かなかったと思います。ありがとうございました。

Sign in to comment.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!