MATLAB: Can’t the standalone application find the desired version of Python

MATLAB Compiler

I have a MATLAB executable which does a bunch of things, but in the beginning of the file, I check to see that Python is installed:
function Check_Python()
version = pyversion;
if ~strcmp(version, '2.7')
msgbox('Python 2.7 is not installed/configured correctly!');
When I run the executable on a target machine, it never gets passed this check. This is unexpected, as calling
python --version
in a Windows Command Prompt returns the proper Python installation (version 2.7.X). However, this works fine on the machine that I compiled the application on.
Why can't MATLAB find the Python installation on this machine, and how can I check that the proper version of Python will be used for the application?

Best Answer

  • The application will not be able to locate the Python installation unless you specify its location. In other words, version = pyversion; will assign the version variable as an empty string. Thus, calling strcmp(version, '2.7') will always return false.
    There are a couple of ways that you can handle this check for the installation of Python, but assuming that you are trying to ensure that the proper version of Python is used in the application, you can use the following workflow:
    executable = C:\Python27\python.exe
    version = pyversion(executable);
    disp("Python version doesn’t exist");
    Here, you can specify the path to the Python executable that you wish to use. If this file doesn’t exist, an error will be thrown by pyversion and caught. The application will then display the error message. Upon success, the pyversion command will specify which Python interpreter to use for the remainder of the application. For more information about pyversion usage, see the following documentation page: