python外部库matlab_使用system()从MATLAB调用Python:导入非标准Python库时出现问题...

test1.py contains:

import sys

print 'ok'

test2.py contains:

import sys

import numpy as np

print 'ok'

Both python test1.py and python test2.py work fine.

When I'm in MATLAB, system('python test1.py') works while system('python test2.py') doesn't work and throw the following error message:

>> system('python test2.py')

Traceback (most recent call last):

File "test.py", line 3, in

import numpy as np

File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 137, in

import add_newdocs

File "/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 9, in

from numpy.lib import add_newdoc

File "/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 13, in

from polynomial import *

File "/usr/lib/python2.7/dist-packages/numpy/lib/polynomial.py", line 17, in

from numpy.linalg import eigvals, lstsq

File "/usr/lib/python2.7/dist-packages/numpy/linalg/__init__.py", line 48, in

from linalg import *

File "/usr/lib/python2.7/dist-packages/numpy/linalg/linalg.py", line 23, in

from numpy.linalg import lapack_lite

ImportError: /afs/csail.mit.edu/system/common/matlab/2012a/sys/os/glnxa64/libgfortran.so.3: version `GFORTRAN_1.4' not found (required by /usr/lib/liblapack.so.3gf)

Full stack:

I use Matlab 2012a x64 on Ubuntu 12.04 with Python 2.7. Any idea why Python called from MATLAB fails to import non-standard Python libraries (here Numpy, but I had the same issue with Scipy)? Note that everything works fine on my Windows computer.

解决方案

The same problem is on Ubuntu 14.04 x64 with Matlab R2013a.

The problem is that matlab comes with some of its own libraries, in this case libgfortran.so.3 instead of using the system ones. From what I googled they are usually outdated, and numpy requires newer versions. Thus there is a problem.

In Ubuntu, it was enough to change the libraries. Don't know how to do it on windows ( I guess it would be somehow similar), but in Ubuntu it is as follows:

First: go to:

`cd /usr/local/MATLAB/R2013a/sys/os/glnxa64`

Second: make backup of matlab's libgfortran.so.3:

`sudo mv libgfortran.so.3 libgfortran.so.3.bck`

Third: sym link system library:

`sudo ln -s /usr/lib/x86_64-linux-gnu/libgfortran.so.3`

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值