Borrar filtros
Borrar filtros

ExecutionMode set to pyenv in matlab batch mode is not persistent

5 visualizaciones (últimos 30 días)
Silvio Traversaro
Silvio Traversaro el 26 de Abr. de 2023
Respondida: Mann Baidi el 31 de Ag. de 2023
According to pyenv documentation (from https://mathworks.com/help/matlab/ref/pyenv.html):
> Use pyenv to change the default version or execution mode of the Python® interpreter. These changes are persistent across different MATLAB® sessions.
However, in both R2022a on Windows and R2022b on Linux I am experiencing that the changes done by pyenv are not persistent when they are done in batch mode.
In particular, the following happens. If I just call, it gives the value that I set in the MATLAB gui:
matlab -batch "pyenv().ExecutionMode"
ans =
ExecutionMode enumeration
OutOfProcess
However, if I try to set the value in batch mode, it does not seem that the changes are saved. It is trivial to see this by executing in sequence:
matlab -batch "pyenv().ExecutionMode"
matlab -batch "pyenv(ExecutionMode='InProcess')"
matlab -batch "pyenv().ExecutionMode"
matlab -batch "pyenv(ExecutionMode='OutOfProcess')"
matlab -batch "pyenv().ExecutionMode"
I would expect that the first call returns the value of ExecutionMode already set, while the third and the fifth command return `OutOfProcess` and `InProcess` . Instead, this does not happens, and the value set is always the one set originally:
C:\Users\STraversaro>matlab -batch "pyenv().ExecutionMode"
ans =
ExecutionMode enumeration
OutOfProcess
C:\Users\STraversaro>matlab -batch "pyenv(ExecutionMode='InProcess')"
ans =
PythonEnvironment with properties:
Version: ""
Executable: ""
Library: ""
Home: ""
Status: NotLoaded
ExecutionMode: InProcess
C:\Users\STraversaro>matlab -batch "pyenv().ExecutionMode"
ans =
ExecutionMode enumeration
OutOfProcess
C:\Users\STraversaro>matlab -batch "pyenv(ExecutionMode='OutOfProcess')"
ans =
PythonEnvironment with properties:
Version: ""
Executable: ""
Library: ""
Home: ""
Status: NotLoaded
ExecutionMode: OutOfProcess
C:\Users\STraversaro>matlab -batch "pyenv().ExecutionMode"
ans =
ExecutionMode enumeration
OutOfProcess
Is this the expected behaviour? There is any way of settng this value in a persistent way in batch mode? Thanks a lot in advance!

Respuestas (2)

Mann Baidi
Mann Baidi el 25 de Ag. de 2023
Hi Silvio,
I understand that you are facing issue in changing the pyenv.ExecutionMode() using the batch command. I suggest you try changing the variable using the MATLAB command window.
You can take the reference from the following link.
Hope this helps!
  1 comentario
Silvio Traversaro
Silvio Traversaro el 28 de Ag. de 2023
Editada: Silvio Traversaro el 28 de Ag. de 2023
Thanks for the reply. For our use case, we would need to the change the `pyenv.ExecutionMode()` in an automatic way in a script, without any user intervention. Do you know have any idea if we can do that via the MATLAB command window? Thanks!

Iniciar sesión para comentar.


Mann Baidi
Mann Baidi el 31 de Ag. de 2023
Hi,
I think you can directly change the ExecutionMode using script also, You can just type:
pyenv()
ans =
PythonEnvironment with properties: Version: "3.10" Executable: "/usr/bin/python3" Library: "libpython3.10.so.1.0" Home: "/usr" Status: NotLoaded ExecutionMode: InProcess
Then change the Execution Mode
pyenv("ExecutionMode","OutOfProcess")
ans =
PythonEnvironment with properties: Version: "3.10" Executable: "/usr/bin/python3" Library: "libpython3.10.so.1.0" Home: "/usr" Status: NotLoaded ExecutionMode: OutOfProcess
The pyenv.ExecutionMode would then be:
pyenv().ExecutionMode
ans =
ExecutionMode enumeration OutOfProcess

Categorías

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

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by