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`