PythonEnvironment - Python environment information - MATLAB (original) (raw)
Main Content
Python environment information
Description
PythonEnvironment
objects contain information about the settings and status of the Python® interpreter. MATLAB® communicates with the interpreter when you call a py.
command. Python environment information is persistent across different MATLAB sessions.
Creation
To create a PythonEnvironment
object or change the settings, call pyenv.
MATLAB selects and loads a Python interpreter when you type a Python expression from MATLAB using the py
namespace, for example,py.list
. To change the interpreter:
- If Python is loaded in
InProcess
ExecutionMode, then restart MATLAB and run pyenv with the new version information. - If Python is loaded in
OutOfProcess
mode, restart MATLAB and run pyenv with the new version information.
Properties
Version
— Python version
string
This property is read-only.
Python version, returned as a string. To set the Version
property, call pyenv
with the version
argument set to a version number that MATLAB supports. For information about supported versions, see Configure Your System to Use Python.
Example: "3.10"
Executable
— Name of Python executable file
string
This property is read-only.
Name of the Python executable file, returned as a string. To set theExecutable
property, call pyenv
with theversion
argument set to a relative or absolute path to the Python executable file.
Example: "/usr/local/bin/python"
Library
— Shared library file
string
This property is read-only.
Shared library file, returned as a string.
Example: "libpython3.10.so.1.0"
Home
— Home folder
string
This property is read-only.
Home folder, returned as a string.
Example: "/usr/local/bin/../.."
Status
— Process status
NotLoaded
(default) | Loaded
| Terminated
Process status, specified as NotLoaded
,Loaded
, or Terminated
.
Example: Terminated
ExecutionMode
— Execution mode
InProcess
(default) | OutOfProcess
Execution mode indicating whether to run Python scripts in the same process as MATLAB, specified as InProcess
orOutOfProcess
. To set the ExecutionMode
property, call pyenv
with the ExecutionMode
argument.
Example: OutOfProcess
ProcessID
— Process ID
string
This property is read-only.
Process ID that the Python interpreter is running on, returned as a string. IfExecutionMode
is InProcess
, thenProcessID
is the MATLAB process ID. If Status
is notLoaded
, then ProcessID
is empty.
Example: "9388"
ProcessName
— Process name
string
This property is read-only.
Process name in registry, returned as a string.
Example: "MATLABPyHost"
Object Functions
terminate | Terminate process associated with Python interpreter |
---|
Examples
Display Python Environment for Your System
pe =
PythonEnvironment with properties:
Version: "3.10"
Executable: "C:\Python310\pythonw.exe"
Library: "C:\windows\system32\python310.dll"
Home: "C:\Python310"
Status: NotLoaded
ExecutionMode: OutOfProcess
Limitations
- Saving (serializing)
PythonEnvironment
objects into a MAT-file is not supported.
Version History
Introduced in R2019b