Contenido principal

Volver a cargar un intérprete de Python fuera de proceso

Cuando ejecuta el intérprete de Python® fuera de proceso, puede terminar el intérprete e iniciar uno nuevo, posiblemente con ajustes de versión diferentes, sin reiniciar MATLAB®.

Para volver a cargar un intérprete de Python dentro de proceso, consulte el ejemplo Volver a cargar un módulo de Python modificado definido por el usuario.

Este ejemplo supone que dispone de las versiones 3.9 y 3.10 de Python. Si el intérprete ya está cargado dentro de proceso, reinicie MATLAB.

pe = pyenv;
if pe.Status == 'NotLoaded'
    pyenv(ExecutionMode="OutOfProcess",Version="3.9");
end
py.list; % Call a Python function to load interpreter
pyenv
ans = 
  PythonEnvironment with properties:

          Version: "3.9"
       Executable: "C:\Python39\pythonw.exe"
          Library: "C:\WINDOWS\system32\python39.dll"
             Home: "C:\Python39"
           Status: Loaded
    ExecutionMode: OutOfProcess
        ProcessID: "15176"
      ProcessName: "MATLABPyHost"

Vuelva a cargar el intérprete de la versión 3.10 de Python.

terminate(pyenv)
pyenv(Version="3.10");
py.list; % Reload interpreter
pyenv
ans = 
  PythonEnvironment with properties:

          Version: "3.10"
       Executable: "C:\Python310\pythonw.exe"
          Library: "C:\WINDOWS\system32\python310.dll"
             Home: "C:\Python310"
           Status: Loaded
    ExecutionMode: OutOfProcess
        ProcessID: "24840"
      ProcessName: "MATLABPyHost"

Consulte también

Temas