pyrunsfile doesn't work when python script includes "import"

15 次查看(过去 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.

回答(1 个)

MJFcoNaN
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.

Community Treasure Hunt

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

Start Hunting!

Translated by