ExecutionMode set to pyenv in matlab batch mode is not persistent

6 次查看(过去 30 天)
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!

回答(2 个)

Mann Baidi
Mann Baidi 2023-8-25
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 个评论
Silvio Traversaro
Silvio Traversaro 2023-8-28
编辑:Silvio Traversaro 2023-8-28
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!

请先登录,再进行评论。


Mann Baidi
Mann Baidi 2023-8-31
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

类别

Help CenterFile Exchange 中查找有关 Call Python from MATLAB 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by