matlabでpythonモジュール(solve_ivp)を実行できない。
24 views (last 30 days)
Show older comments
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/
0 Comments
Accepted Answer
Kojiro Saito
on 21 Apr 2022
MATLAB R2021a Update6、Python 3.8.10、Scipy 1.7.3及び1.8.0で試しましたが私の環境では再現しませんでした。
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
More Answers (0)
See Also
Categories
Find more on MATLAB の Python ライブラリ in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!