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

19 visualizaciones (últimos 30 días)
인성 이
인성 이 el 3 de Jul. de 2022
Respondida: MJFcoNaN el 3 de Jul. de 2022
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.

Respuestas (1)

MJFcoNaN
MJFcoNaN el 3 de Jul. de 2022
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.

Categorías

Más información sobre Call Python from MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by