Why can't my standalone application find the desired version of Python?

2 views (last 30 days)
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!');
else
msgbox('Good!');
end
end
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?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 21 Sep 2020
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:
try
executable = C:\Python27\python.exe
version = pyversion(executable);
disp(version);
catch
disp("Python version doesn’t exist");
end
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:

More Answers (0)

Tags

No tags entered yet.

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!