MATLAB does not see that an older version of python has been uninstalled
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I have installed python 3.9 and uninstalled python 3.8 from:
- /usr/local/bin/
- /Library/Frameworks/Python.framework/Versions/
- /Applications/
However, when I run pyenv I stil get this:
ans =
PythonEnvironment with properties:
Version: "3.8"
Executable: "/usr/local/bin/python3.8"
Library: "/Library/Frameworks/Python.framework/Versions/3.8/lib/libpython3.8.dylib"
Home: "/Library/Frameworks/Python.framework/Versions/3.8"
Status: NotLoaded
ExecutionMode: InProcess
So when my code trys to run a py.funcname it cannot load 3.8 to run it.
On my personal machine I can change it with:
>> pyenv('Version','/usr/local/bin/python3.9')
However I am deploying an app designer app and will not be able to tell if a user has uninstalled a version of python. Furthermore, the ways to check what version of python matlab will use come up with the uninstalled version. I could make a startup user input window to select what version they have installed and change it there, but the whole purpose of the app is to be user friendly and that would be anoying and confuse some people.
Is there a way for matlab to check which versions of python are installed and select the ones that are actually there?
(I believe i could do this in the startup Fcn using system comands but I hope there is a better way)
Thank you for any assistance.
0 comentarios
Respuestas (1)
arushi
el 9 de Oct. de 2023
Hi James,
I understand that you want the app-designer app to detect the python versions installed and select the required one.
Please follow the below mentioned steps to detect and select the version:
1. Check the installed Python versions:
pyVersions = pyversion;
The `pyversion` function returns a structure containing information about the installed Python versions.
2. Iterate through the installed Python versions and select the desired one:
desiredVersion = '3.8'; % Specify the desired Python version
selectedVersion = '';
for i = 1:numel(pyVersions)
if strcmp(pyVersions(i).Version, desiredVersion)
selectedVersion = pyVersions(i).Executable;
break;
end
end
In this example, the `desiredVersion` variable is set to the Python version you want to select. The loop iterates through the `pyVersions` structure and checks if the version matches the desired version. If a match is found, the `selectedVersion` variable is set to the executable path of the desired Python version.
3. Set the selected Python version for MATLAB:
if ~isempty(selectedVersion)
pyversion(selectedVersion);
else
error('Desired Python version not found.');
end
The `pyversion` function is used to set the selected Python version for MATLAB. If a matching version is found and `selectedVersion` is not empty, the selected version is set using `pyversion`. Otherwise, an error is thrown indicating that the desired Python version was not found.
By incorporating these steps into your app, you can check the installed Python versions and automatically select the desired version without requiring manual input from the user.
Hope this answers your question.
0 comentarios
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!