問(wèn)題描述
我已按照 Anaconda 答案中的說(shuō)明安裝了官方 MATLAB 引擎在 Linux 上安裝 Matlab 引擎 到運(yùn)行 Python3.5 的 Anaconda 虛擬環(huán)境.我現(xiàn)在可以導(dǎo)入 matlab
和 matlab.engine
而不會(huì)收到錯(cuò)誤.但是,當(dāng)我嘗試:matlab.engine.start_matlab()
,我得到分段錯(cuò)誤(核心轉(zhuǎn)儲(chǔ))"
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 環(huán)境中設(shè)置 LD_LIBRARY_PATH(以防萬(wàn)一):export LD_LIBRARY_PATH=/System/Library/Frameworks/Python.framework/Versions/Current/lib:$LD_LIBRARY_PATH代碼>,但無(wú)濟(jì)于事.據(jù)我所知,該路徑也不存在,所以我也嘗試過(guò)
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 虛擬環(huán)境中啟動(dòng) matlab 引擎/從 Python 調(diào)用 Matlab 腳本?
So how can I start the matlab engine/call Matlab scripts from Python from within a Anaconda virtual environment?
順便說(shuō)一句,我在 Ubuntu 上
I'm on Ubuntu, by the way
推薦答案
簡(jiǎn)答:有兩個(gè)問(wèn)題需要解決
Short answer: there were two problems that needed to be fixed
$LD_LIBRARY_PATH
應(yīng)該不包含 Anaconda 安裝的路徑.根據(jù) conda 文檔,不鼓勵(lì)添加這樣的路徑:https://conda.io/docs/building/shared-libraries.html,但有些軟件包可能會(huì)這樣做,從而導(dǎo)致分段錯(cuò)誤.- 需要從正確版本的 libpythonXXX.dylib 文件到/usr/lib/的符號(hào)鏈接,以便 MATLAB 可以找到正確的 Python
$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.- A symbolic link is needed from a libpythonXXX.dylib file of the right version to /usr/lib/, so that MATLAB can find the right Python
長(zhǎng)答案:使用 MATLAB Engine 和 Anaconda 的完整安裝說(shuō)明
Long answer: complete installation instructions for using MATLAB Engine with Anaconda
- 安裝支持您要使用的 Python 的 MATLAB 版本.確保此特定 MATLAB 安裝已激活
- 打開(kāi)終端并轉(zhuǎn)到包含 MATLAB 安裝的 Python 引擎的文件夾:
cd "/usr/local/MATLAB/R2017a/extern/engines/python"
- 使用您要使用的 Python 版本運(yùn)行 setup.py,并為 Anaconda 環(huán)境位置添加前綴:
sudo python3.5 setup.py install --prefix="/your_path_to_anaconda3/envs/your_env"
.此時(shí),您應(yīng)該能夠從 Anaconda 環(huán)境的 Python 中import matlab
和matlab.engine
,但是,在我的情況下,啟動(dòng)引擎會(huì)導(dǎo)致分段錯(cuò)誤. - 找到正確版本的 libpython 文件.您的 Anaconda 環(huán)境應(yīng)該包含它:
find/your_path_to_anaconda3/envs/your_env/-name libpython*
.就我而言,這返回了:- /.../lib/libpython3.so
- /.../lib/python3.5/config-3.5m/libpython3.5m.a
- /.../lib/libpython3.5m.so.1.0
- /.../lib/libpython3.5m.so
- Install a MATLAB version that supports the Python you want to use. Ensure that this particular MATLAB installation is activated
- Open a terminal and go to the folder containing the Python engine of the MATLAB installation:
cd "/usr/local/MATLAB/R2017a/extern/engines/python"
- Run setup.py with the Python version you want to use, and prefix the Anaconda environment location:
sudo python3.5 setup.py install --prefix="/your_path_to_anaconda3/envs/your_env"
. At this point you should be able toimport matlab
andmatlab.engine
from within the Python of your Anaconda environment, but, in my case, starting the engine gave the segmentation error. - Find the libpython file of the right version. Your Anaconda environment should contain it:
find /your_path_to_anaconda3/envs/your_env/ -name libpython*
. In my case this returned:- /.../lib/libpython3.so
- /.../lib/python3.5/config-3.5m/libpython3.5m.a
- /.../lib/libpython3.5m.so.1.0
- /.../lib/libpython3.5m.so
這篇關(guān)于在 anaconda 虛擬環(huán)境中啟動(dòng) Matlab 引擎返回“分段錯(cuò)誤(核心轉(zhuǎn)儲(chǔ))"的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!