pyversion

Change default version of Python interpreter

Syntax

pyversion
[version, executable, isloaded] = pyversion
___ = pyversion version
___ = pyversion executable

Description

example

pyversion displays details about the current Python® version.

[version, executable, isloaded] = pyversion returns Python version information.

example

___ = pyversion version changes the default Python version on Microsoft® Windows® platforms. You can request any of the outputs from previous syntaxes. The setting is persistent across MATLAB® sessions.

Note

You cannot change the version after MATLAB loads Python. To change the version if Python is loaded already, restart MATLAB, and then call pyversion.

___ = pyversion executable specifies the full path to the Python executable. You can use this syntax on any platform or for repackaged CPython implementation downloads.

Examples

collapse all

pyversion
       version: '2.7'
    executable: 'C:\Python27\python.exe'
       library: 'C:\windows\system32\python27.dll'
          home: 'C:\Python27'
      isloaded: 0
[v, e, isloaded] = pyversion;
if isloaded
    disp('To change the Python version, restart MATLAB, then call pyversion.')
else
    pyversion 2.7
end

Input Arguments

collapse all

Python version number, specified as a string or character vector. The version must contain the major and minor version numbers separated by a period. (Windows platform only)

pyversion looks for the version in the Windows registry. If you download the Python application from www.python.org/downloads, the installation automatically adds the version to the registry. If you download the application from a different source, you must either add it to the registry or use the pyversion(executable) syntax to change the version.

Example: 3.5

Name of an existing Python executable file, specified as a string or character vector. This argument must contain the name of the Python executable file, and it can contain the full path.

Example: C:\Python33\python.exe

Example: /usr/bin/python

Output Arguments

collapse all

Python version number, returned as a character vector.

Name of Python executable file, returned as a character vector.

Version loaded indicator specifying if this version is loaded, returned as logical. MATLAB loads Python when you type a py. command.

If MATLAB cannot load Python, isloaded is 0 and MATLAB displays Undefined variable "py" or function "py.command" when you type a py. command.

Limitations

  • Do not use pyversion to set the version in a MATLAB function containing Python commands. Before MATLAB executes the pyversion function, it loads the Python interpreter when it processes a Python command in the function.

See Also

Introduced in R2014b