ExecutionMode set to pyenv in matlab batch mode is not persistent

6 views (last 30 days)
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!

Answers (2)

Mann Baidi
Mann Baidi on 25 Aug 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 Comment
Silvio Traversaro
Silvio Traversaro on 28 Aug 2023
Edited: Silvio Traversaro on 28 Aug 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!

Sign in to comment.


Mann Baidi
Mann Baidi on 31 Aug 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

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!