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
InProcess
ExecutionMode
, then restart MATLAB and runpyenv
with the new version information.If Python is loaded in
OutOfProcess
mode, restart MATLAB and runpyenv
with the new version information.
MATLAB accesses these settings when loading the Python interpreter:
User settings for the Python environment, configured using the
pyenv
function. If the version you specify conflicts with the version specified byPYTHONHOME
, then delete the environment variable before callingpyenv
. The value set bypyenv
is persistent across MATLAB sessions. For more information, see Set Python Version on Windows Platform or Set Python Version on Mac and Linux Platforms.PYTHONHOME
environment variable, specifies where to find the standard Python libraries if the value ofpyenv.Status
isNotLoaded
. To view the value of the variable in MATLAB, typegetenv("PYTHONHOME")
. For more information, see Use PYTHONHOME Environment Variable.System
PATH
environment 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. Use this syntax with any of the arguments in
previous syntaxes.
Examples
Input Arguments
Version History
Introduced in R2019b