pyrunsfile doesn't work when python script includes "import"
4 次查看(过去 30 天)
显示 更早的评论
Hi.
I want to run a python script using pyrunfile.
I have confirmed that a very simple python script works through pyrunfile.
such as Ex.py :
% Ex.py
x = 1+1;
print(x);
However, if I add the code to import additionally installed libraries such as numpy, matplotlib, and tensorflow, the following error occurs.
Python Error: ModuleNotFoundError: No module named 'numpy'
I have obviously installed numpy, and when I run the python script through pycharm it works fine.
Like many advices before, I tried creating a virtual environment via anaconda prompt, installing numpy first and then running matlab, but the same problem persisted.
Am I missing something when I load the python environment to matlab?
I am using matlab 2021b, and python 3.7.9
Please help.
Thank you.
0 个评论
回答(1 个)
MJFcoNaN
2022-7-3
Hello,
As I know, there were some python packages that some versions of matlab can't load if you installed them in virtual environment (such as from conda), and numpy was certainly one of them.
I am not sure how newer matlab deal with it, but I will suggest you try to avoid anaconda and only use the original python, pip, then make matlab load it.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call Python from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!