Main Content

PythonEnvironment

Python environment information

Description

PythonEnvironmentobjects contain information about the settings and status of the Python®interpreter. MATLAB®communicates with the interpreter when you call apy.command. Python environment information is persistent across different MATLAB sessions.

Creation

To create aPythonEnvironmentobject or change the settings, callpyenv. The Python interpreter is loaded when you call a Python command in thepypackage. You cannot change the interpreter after MATLAB loads Python. To change the interpreter, restart MATLAB, and then callpyenv.

Properties

expand all

Python version, specified as a read-only string. To set theVersionproperty, callpyenvwith the'Version'argument set to a version number that MATLAB supports. For information about supported versions, seeConfigure 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 theExecutableproperty, callpyenvwith 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 asLoaded,NotLoaded, orTerminated.

Example:Terminated

Execution mode indicating whether to run Python scripts in the same process as MATLAB, specified asInProcessorOutOfProcess. To set theExecutionModeproperty, callpyenvwith theExecutionModeargument.

Example:OutOfProcess

Process ID that the Python interpreter is running on, specified as a read-only string. IfExecutionModeisInProcess, thenProcessIDis the MATLAB process ID. IfStatusis notLoaded, thenProcessIDis empty.

Example:"9388"

Data Types:string

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

Example:"MATLABPyHost"

Data Types:string

Object Functions

terminate Terminate process associated withPythoninterpreter

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)PythonEnvironmentobjects into a MAT-file is not supported.

Version History

Introduced in R2019b