Reputation: 8246
I would like to know if there is a way I could check from my python code if matlab exists on a system. So far the only thing I can come up with is: exists = os.system("matlab")
and then parse the exists for a command not found
. But I'm almost sure this will:
So is there any way I could check if a matlab installation is available on the system from python ?
Regards, Bogdan
Upvotes: 2
Views: 525
Reputation: 492
Another way would be to to use shutil
import shutil
mt = shutil.which("matlab")
If 'matlab' is found it returns the path where it was found, else it returns 'NoneType'. You may check for 'matlab' or 'matlab.exe' depending on the OS.
Upvotes: 0
Reputation: 43219
Assuming your system call works, you can check the path for matlab.exe like this:
import os
def matlab_installed():
for path in os.environ["PATH"].split(";"):
if os.path.isfile(os.path.join(path, "matlab.exe")):
return True
return False
For Unix, you have to change split(";") to split(":") and "matlab.exe" to whatever the matlab executable is called under Unix.
Upvotes: 1