ExecutionMode set to pyenv in matlab batch mode is not persistent

6 ビュー (過去 30 日間)
Silvio Traversaro
Silvio Traversaro 2023 年 4 月 26 日
回答済み: Mann Baidi 2023 年 8 月 31 日
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 Center および File ExchangeCall 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