Borrar filtros
Borrar filtros

How to call python in matlab

47 visualizaciones (últimos 30 días)
Jeniffer Viegas
Jeniffer Viegas el 20 de Jul. de 2020
Comentada: Ken Bannister el 26 de Jul. de 2022
Hello,
I'm trying to call python from matlab but I'm getting the message:
py.list({'Monday','Tuesday','Wednesday','Thursday','Friday'})
Unable to resolve the name py.list.
For all code I type with py. this happens.
I also have tried pyenv, and I got:
>> pyenv
ans =
PythonEnvironment with properties:
Version: "3.7"
Executable: "C:\Users\Familia\.conda\envs\matlab\python.exe"
Library: "C:\Users\Familia\.conda\envs\matlab\python37.dll"
Home: "C:\Users\Familia\.conda\envs\matlab"
Status: NotLoaded
ExecutionMode: InProcess
Maybe the problem is the status? NotLoaded? How do I change that for loaded?
I also have tried to modify the path for another python I have installed, not from Anaconda with this command
pe = pyenv('Version','C:\Users\Familia\AppData\Local\Microsoft\WindowsApps\python.exe')
But then, I got this error:
Error using pyenv
Path argument does not specify a valid executable.
I really need to run python in matlab and I don't know what to do
  1 comentario
Ken Bannister
Ken Bannister el 26 de Jul. de 2022
I don't even get any useful response when I run "pyenv" in MATLAB 2022a, even though I have donwloaded Python 3.9.13. After downloading Python, what else has to be done to get MATLAB to "talk" to it?

Iniciar sesión para comentar.

Respuesta aceptada

Jeniffer Viegas
Jeniffer Viegas el 21 de Jul. de 2020
I found the solution.
For me was install again python and during the instalation I chose add path to environment variable and install to all users.
Then the command pyversion('Path') worked.

Más respuestas (1)

Abhishek Gangwar
Abhishek Gangwar el 20 de Jul. de 2020
  • Check if your python executable path is correct?
  • Set the python environment with correct python executalbe first it will show the status as "NotLoaded", run any "py" command, check the status it will show status ass "Loaded".
And there is an alternate way to use python scripts and functions from matlab, using "system()" function as,
system('python <script> <arguments>')
For example,
system('python /Users/myName/pathToScript/sqr.py 2')
  2 comentarios
Jeniffer Viegas
Jeniffer Viegas el 20 de Jul. de 2020
How do I check if the python executable path is correct?
Abhishek Gangwar
Abhishek Gangwar el 21 de Jul. de 2020
from python interpreter hit these commands,
import sys
print(sys.executable)

Iniciar sesión para comentar.

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by