pyenv
Change default environment of Python interpreter
Description
Use pyenv to change the default version or execution mode of
the Python® interpreter. These changes are persistent across different MATLAB® sessions.
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
InProcessExecutionMode, then restart MATLAB and callpyenvwith the new version information or execution mode.If Python is loaded in
OutOfProcessmode, then terminate the process associated with the Python interpreter by callingbefore callingterminatepyenvwith the new version information or execution mode.
MATLAB accesses these settings when loading the Python interpreter:
User settings for the Python environment, configured using the
pyenvfunction. If the version you specify conflicts with the version specified byPYTHONHOME, then delete the environment variable before callingpyenv. The value set bypyenvis persistent across MATLAB sessions. For more information, see Set Python Version on Windows Platform or Set Python Version on Mac and Linux Platforms.PYTHONHOMEenvironment variable, specifies where to find the standard Python libraries if the value ofpyenv.StatusisNotLoaded. To view the value of the variable in MATLAB, typegetenv("PYTHONHOME"). For more information, see Use PYTHONHOME Environment Variable.System
PATHenvironment variable. To view the system path in MATLAB, typegetenv("PATH").Windows® registry.
pyenv displays details about the current (default) Python environment.
pyenv( specifies parameters for
setting the Python environment. For example, Name=Value)pyenv(Version="3.10") changes
the default Python version on Microsoft®
Windows platforms to 3.10.
pe = pyenv(___) additionally returns environment
details as a PythonEnvironment object.
Examples
Name-Value Arguments
Version History
Introduced in R2019b