Why can't my standalone application find the desired version of Python?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 21 de Sept. de 2020
Respondida: MathWorks Support Team
el 21 de Sept. de 2020
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?
Respuesta aceptada
MathWorks Support Team
el 21 de Sept. de 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:
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Call Python from MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!