简体   繁体   English

什么是64位的Matlab安装目录或如何在Python中获取它?

[英]What is the Matlab install directory on 64bit or how to get it in Python?

I have Matlab2013b on my system at : 我的系统上有Matlab2013b:

C:\\Program Files\\MATLAB\\R2013b\\bin C:\\ Program Files \\ MATLAB \\ R2013b \\ bin

I am writing Python script that searches for Matlab.exe first at this location and then at location for 64 bit. 我正在编写Python脚本,首先在此位置搜索Matlab.exe,然后在64位位置搜索。 The Python script will be run on a server which might have a 64 bit instead of 32 bit. Python脚本将在可能具有64位而不是32位的服务器上运行。 So, I need to search for both locations. 所以,我需要搜索这两个位置。
Since I don't have 64 bit version on my machine, I don't know the location. 由于我的机器上没有64位版本,我不知道位置。

I am speculating it will be: 我猜测它将是:

C:\\Program Files (x86)\\MATLAB\\R2013b\\bin C:\\ Program Files(x86)\\ MATLAB \\ R2013b \\ bin

But can anybody confirm that? 但任何人都可以证实吗?
Thanks 谢谢
sedy sedy

You can read out the environment variable PATH (I'd say it's quite sure MATLAB it's included) and use some string operations to get the Matlab path: 你可以读出环境变量PATH (我说它非常肯定包含MATLAB )并使用一些字符串操作来获取Matlab路径:

import os
path = os.environ.get('path')
pathlist = path.split(';')
matlabpath = [s for s in pathlist if all(x in s for x in ['MATLAB','R','bin'])]
print(matlabpath)

this way you don't need to speculate what I would consider a generally bad programming practice. 这样你就不需要推测我认为通常糟糕的编程习惯。


In my case there is also an toolbox polyspace on the same path, you need to exclude that: 在我的情况下,在同一路径上还有一个工具箱多边形 ,您需要排除:

matlabpath = [s for s in pathlist if all(x in s for x in ['MATLAB','R','bin']) and not 'polyspace' in s]

There may be other toolboxes writing itself into path - it could be cumbersome to exclude all of them, so the easiest would be to just return the shortest of all Matlab related paths: 可能有其他工具箱将自己写入路径 - 排除所有这些工具箱可能很麻烦,因此最简单的方法是返回所有Matlab相关路径中最短的路径:

import os
path = os.environ.get('path')
pathlist = path.split(';')
matlabpath = min([s for s in pathlist if 'MATLAB' in s], key=len) 
print(matlabpath)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM