How can I run python script file programmed in anaconda virtual environment in MATLAB?
Show older comments
I have a python code that is programmed in virtual environment of anaconda, and I want to run this code in matlab by using 'pyrunfile' function. I set python interpreter as that of virtual environment using 'pyversion' function and check the change by using 'pyenv' function.
After that setting, if I run a python code in matlab(I use 'pyrunfile'), error [Python Error: OSError: [WinError 126] The specified module could not be found. Error loading ...] occurs when import torch or numpy module.
I think this error occurs because the executor of python is not set as python interpreter of virtual env. of anaconda but matlab executor. But I don't know how to solve this error.
I checked there is no error when running the python code in anaconda prompt.
MATLAB code is as,
filename = 'C:/Users/yser/PycharmProjects/pytorch_based_code/Defined_RNN_v4_1.py';
pred_y = pyrunfile(filename, 'prediction', MATLAB_input=Train_set_in);
% prediction: output variable in python code
% MATLAB_input: input variable in python code
% Train_set_in: arg. of matlab
Accepted Answer
More Answers (0)
Categories
Find more on Call Python from MATLAB 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!