python检查matlab安装

2024-06-16 09:47:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我想知道是否有一种方法可以从python代码中检查系统上是否存在matlab。到目前为止,我唯一能想到的就是:exists = os.system("matlab"),然后为command not found解析exists。但我几乎肯定这会:

  1. 启动matlab,以防系统中存在它。我不想要这个。在
  2. 响应可能因我运行的系统而异?在

那么有没有什么方法可以让我检查一下python系统上是否有matlab安装?在

谨致问候, 博格丹


Tags: 方法代码os系统existsnotsystemcommand
1条回答
网友
1楼 · 发布于 2024-06-16 09:47:03

假设您的系统调用正常,您可以检查matlab.exe像这样:

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

对于Unix,必须将split(“;”)更改为split(“:”)和“matlab.exe在Unix下调用的matlab可执行文件。在

相关问题 更多 >