服务器中安装Matlab for Python

原文链接: 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" install

Build 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"

 具体操作其实很简单:

首先进入matlab安装目录,可以通过whereis matlab简化步骤:

(base) XXX@gpu01:/usr/local/MATLAB/R2018a/extern/engines/python$

之后切换环境以保证安装在了你想要它安装的那个环境里:

conda activate python36

之后指定目录安装即可:

python3.6 setup.py build --build-base="/share/home/XXX/matlab/" install --prefix="/share/home/XXX/anaconda3/envs/python36"

其中,XXX即为用户名,这两个目录显然普通用户是有写入权限的。

 

验证成功:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

R.X. NLOS

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值