所以我让 Matlab “呼唤”到一个外部 python 库。Matlab 端使用 dlmwrite() 将双精度矩阵写入文件,通过连接构建命令字符串(它只是一行):
#/bin/tcsh
python myscript.py -option1 long_file_path1 long_file_path2 long_file_path3<br>
这个可怕的长命令被写到一个 shell 脚本中,让它命名为 caller.sh,然后 Matlab 使用 system() 命令成功地在 caller.sh 上调用 chmod 755。
但是,当我尝试在 shell 脚本(即 system(['sh caller.sh']) 上实际运行 system() 命令时,它会因一声巨响而崩溃:
Traceback (most recent call last):
File "/homes/sb1006/PhD_Year_1/code//my_libs/LSTM/python/monohiddenlayer_regression_LSTM.py", line 1, in <module>
import pybrain
File "/homes/sb1006/PhD_Year_1/code/my_libs/LSTM/python/pybrain/__init__.py", line 1, in <module>
from structure.__init__ import *
File "/homes/sb1006/PhD_Year_1/code/my_libs/LSTM/python/pybrain/structure/__init__.py", line 1, in <module>
from connections.__init__ import *
File "/homes/sb1006/PhD_Year_1/code/my_libs/LSTM/python/pybrain/structure/connections/__init__.py", line 1, in <module>
from full import FullConnection
File "/homes/sb1006/PhD_Year_1/code/my_libs/LSTM/python/pybrain/structure/connections/full.py", line 3, in <module>
from scipy import reshape, dot, outer
File "/usr/lib/python2.7/dist-packages/scipy/__init__.py", line 78, in <module>
from numpy import show_config as show_numpy_config
File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 137, in <module>
import add_newdocs
File "/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 13, in <module>
from polynomial import *
File "/usr/lib/python2.7/dist-packages/numpy/lib/polynomial.py", line 17, in <module>
from numpy.linalg import eigvals, lstsq
File "/usr/lib/python2.7/dist-packages/numpy/linalg/__init__.py", line 48, in <module>
from linalg import *
File "/usr/lib/python2.7/dist-packages/numpy/linalg/linalg.py", line 23, in <module>
from numpy.linalg import lapack_lite
ImportError: /usr/lib/matlab/R2012a/sys/os/glnxa64/libgfortran.so.3: version 'GFORTRAN_1.4' not found (required by /usr/lib/liblapack.so.3gf)
当我从单独的 shell 运行 caller.sh 时(例如,我设置了一个断点,并将 system() 中的命令复制粘贴到终端中),一切运行正常。当我将 caller.sh 的内容直接复制到终端时,它运行良好。
但由于某种原因,Matlab system(['sh caller.sh']) 导致它以最奇怪的方式爆炸,这表明我在自己的 python 脚本中调用的 python 库缺少 Matlab 运行时中的一些线性代数库?!尽管它独立于 Matlab 运行,而且显然如此。我很困惑。