我已按照 Anaconda 答案中的说明安装了官方 MATLAB 引擎在 Linux 上安装 Matlab 引擎 到运行 Python3.5 的 Anaconda 虚拟环境.我现在可以导入 matlab
和 matlab.engine
而不会收到错误.但是,当我尝试:matlab.engine.start_matlab()
,我得到分段错误(核心转储)"
I've installed the official MATLAB Engine by following the instructions from the answer to Anaconda install Matlab Engine on Linux to an Anaconda virtual environment running Python3.5. I can now import matlab
and matlab.engine
without receiving errors. However, when I try:
matlab.engine.start_matlab()
, I get 'Segmentation fault (core dumped)'
我尝试在 conda 环境中设置 LD_LIBRARY_PATH(以防万一):export LD_LIBRARY_PATH=/System/Library/Frameworks/Python.framework/Versions/Current/lib:$LD_LIBRARY_PATH代码>,但无济于事.据我所知,该路径也不存在,所以我也尝试过
export DYLD_LIBRARY_PATH=path_to_anaconda3/envs/myEnv/lib:$LD_LIBRARY_PATH
I've tried setting LD_LIBRARY_PATH from within the conda environment (in case that is even relevant): export LD_LIBRARY_PATH=/System/Library/Frameworks/Python.framework/Versions/Current/lib:$LD_LIBRARY_PATH
, but to no avail. The path doesn't exist either as far as I'm aware, so I've also tried export DYLD_LIBRARY_PATH=path_to_anaconda3/envs/myEnv/lib:$LD_LIBRARY_PATH
那么如何从 Anaconda 虚拟环境中启动 matlab 引擎/从 Python 调用 Matlab 脚本?
So how can I start the matlab engine/call Matlab scripts from Python from within a Anaconda virtual environment?
顺便说一句,我在 Ubuntu 上
I'm on Ubuntu, by the way
简答:有两个问题需要解决
Short answer: there were two problems that needed to be fixed
$LD_LIBRARY_PATH
应该不包含 Anaconda 安装的路径.根据 conda 文档,不鼓励添加这样的路径:https://conda.io/docs/building/shared-libraries.html,但有些软件包可能会这样做,从而导致分段错误.$LD_LIBRARY_PATH
should not contain a path to the Anaconda installation. Adding such a path is discouraged according to the conda documentation: https://conda.io/docs/building/shared-libraries.html, but some packages may do so anyways, causing the segmentation error.长答案:使用 MATLAB Engine 和 Anaconda 的完整安装说明
Long answer: complete installation instructions for using MATLAB Engine with Anaconda
cd "/usr/local/MATLAB/R2017a/extern/engines/python"
sudo python3.5 setup.py install --prefix="/your_path_to_anaconda3/envs/your_env"
.此时,您应该能够从 Anaconda 环境的 Python 中 import matlab
和 matlab.engine
,但是,在我的情况下,启动引擎会导致分段错误.find/your_path_to_anaconda3/envs/your_env/-name libpython*
.就我而言,这返回了:cd "/usr/local/MATLAB/R2017a/extern/engines/python"
sudo python3.5 setup.py install --prefix="/your_path_to_anaconda3/envs/your_env"
. At this point you should be able to import matlab
and matlab.engine
from within the Python of your Anaconda environment, but, in my case, starting the engine gave the segmentation error.find /your_path_to_anaconda3/envs/your_env/ -name libpython*
. In my case this returned:
这篇关于在 anaconda 虚拟环境中启动 Matlab 引擎返回“分段错误(核心转储)"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!