PythonEnvironment

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. The Python interpreter is loaded when you call a Python command in the py package. You cannot change the interpreter after MATLAB loads Python. To change the interpreter, restart MATLAB, and then call pyenv.

Properties

expand all

Python version, specified as a read-only string. To set the Version property, call pyenv with the 'Version' argument set to a MATLAB-supported version number. For information about supported versions, see Configure Your System to Use Python"".

Example: "2.7"

Data Types: string

Name of the Python executable file, specified as a read-only string. To set the Executable property, call pyenv with the 'Version' argument set to the name of the Python executable file and, optionally, the full path.

Example: "/usr/local/bin/python"

Data Types: string

Shared library file, specified as a read-only string.

Example: "libpython2.7.so.1.0"

Data Types: string

Home folder, specified as a read-only string.

Example: "/usr/local/bin/../.."

Data Types: string

Process status, specified as Loaded, NotLoaded, or Terminated.

Example: Terminated

Execution mode indicating whether to run Python scripts in the same process as MATLAB, specified as InProcess or OutOfProcess. To set the ExecutionMode property, call pyenv with the ExecutionMode argument.

Example: OutOfProcess

Process ID that the Python interpreter is running on, specified as a read-only string. If ExecutionMode is InProcess, then ProcessID is the MATLAB process ID. If Status is not Loaded, then ProcessID is empty.

Example: "9388"

Data Types: string

Process name in registry, specified as a read-only string.

Example: "MATLABPyHost"

Data Types: string

Object Functions

terminateTerminate process associated with Python interpreter

Examples

collapse all

pe = pyenv
pe = 

  PythonEnvironment with properties:

          Version: "2.7"
       Executable: "C:\Python27\pythonw.exe"
          Library: "C:\windows\system32\python27.dll"
             Home: "C:\Python27"
           Status: NotLoaded
    ExecutionMode: OutOfProcess
  

Limitations

  • Saving (serializing) PythonEnvironment objects into a MAT-file is not supported.

Introduced in R2019b