原文链接: https://www.computationalimaging.cn/2019/10/matlab-for-python.html
由于训练网络计算损失函数的时候需要进行FFT和稀疏矩阵,使用Python完成非常麻烦,因此希望能够在服务器上安装供Python使用的MATLAB Engine, 但有如下两个问题:
1. 普通MATLAB Engine for Python的安装需要root权限,但我没有;
2. 使用Conda安装了多个环境,如何控制指定环境安装Matlab Engine也是问题。
MATLAB官网给出了有用但不是很详细的解决方案:
By default, the installer builds the engine API for Python® in the matlabroot\extern\engines\python folder. The installer installs the engine in the default Python folder. If you do not have write permission for these folders, then select one of the following nondefault options. If you install in another folder, then update the PYTHONPATH variable to the location of that folder.
Options for building and installing the engine API follow, along with the commands to enter at the operating system prompt.
Build in Nondefault Folder and Install in Default Folder
If you do not have write permission to build the engine in the MATLAB® folder, then use a nondefault folder, builddir.
cd "matlabroot\extern\engines\python" python setup.py build --build-base="builddir" installBuild in Default Folder and Install in Nondefault Folder
If you do not have write permission to install the engine in the default Python folder, then use a nondefault folder, installdir.
cd "matlabroot\extern\engines\python" python setup.py install --prefix="installdir"To include installdir in the search path for Python packages, add installdir to the PYTHONPATH environment variable.
Build and Install in Nondefault Folders
If you do not have write permission for both the MATLAB folder and the default Python folder, then you can specify nondefault folders. Use builddir for the build folder and installdir for the install folder.
cd "matlabroot\extern\engines\python" python setup.py build --build-base="builddir" install --prefix="installdir"具体操作其实很简单:
其中,XXX即为用户名,这两个目录显然普通用户是有写入权限的。
验证成功: