Running a Python Script in Matlab wouldn't execute it
Mostrar comentarios más antiguos
The main issue I am facing is not being able to run a python script outside of Matlab via
system('python pythonFile.py')
If I use the latter method, no errors are shown, but the python code is simply not being executed (I have put "print" functions here and there to check), and I get
ans = -1.0737e+09
as a result, with no output whatsoever.
Whereas, if I run the same script from the command prompt (Anaconda), it works fine. Keep in mind that I have opened Matlab from the same prompt by typing 'matlab' so that I get specific environment variables. The odd thing is, if I remove specific imports such as Keras, Tensorflow, and Numpy libraries from my python code, Matlab is able to run the script fine, i.e., the print functions' output in this case is shown, but of course, the training of my ML model is no longer there. Again, none of this happens if I run the python script from the Anaconda prompt.
I have also tried to use pyenv and py. Once I verified that the pyenv properties such as Version, Executable, etc. are setup, I tried the following via the Matlab Command Window:
py.pythonFile.main
. Although it seems to start to run properly (the very first print statements show in the Command Window) but then Matlab either crashes immediately, just before the import statements of the libraries afore mentioned, or prompts the error:
Unable to resolve the name py.pythonFile.main
(depending on whether I import tensorflow.keras or keras in my python file, respectively).
I have tried echo %path% in my Anaconda prompt, in which the python code runs properly, and used
setenv(path, theEchoedPath)
but I got the same issue.
I need to run the python file from Matlab. Any suggestions?
Libraries used: Tensorflow 1.4.0, Keras 2.2.4. Python version: 3.6.6.
1 comentario
Maen Saassouh
el 16 de Ag. de 2020
Editada: Maen Saassouh
el 17 de Ag. de 2020
Respuestas (0)
Categorías
Más información sobre Call Python from MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!