This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Change default version of Python interpreter


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



pyversion displays details about the current Python® version.

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


___ = pyversion version changes the default Python version on Microsoft® Windows® platforms. The setting is persistent across MATLAB® sessions.

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 full path to Python executable. Use on any platform or for repackaged CPython implementation downloads.


collapse all

       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.')
    pyversion 2.7

Input Arguments

collapse all

Python version number, specified as a string or character vector. 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 from, the installation automatically adds the version to the registry. If you download the Python application from a different source, 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.

Indicates if specified 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.


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

Introduced in R2014b

Was this topic helpful?