MATLAB function is unable to import python library when run as executable file
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jayasuriya Senthilvelan
el 21 de Oct. de 2020
Editada: Jayasuriya Senthilvelan
el 21 de Oct. de 2020
I need to run a python script from my matlab function. I used the following code to do this.
!cd ~ && source ./venv/bin/activate && cd ./LiverSegApp/src/ && python ./SIML_LiverSeg/lib/hnet/test.py
This code goes to my home directory, activates a python virtual environment, then goes to my code directory and runs test.py. I ran this matlab function from MATLAB console/GUI and the python call works perfectly fine. If I run test.py from the terminal inside my virtual environment, everything works perfectly.
However, when I change this matlab function and its auxiliary functions into a executable, and run the executable from the terminal, I get the following error from test.py:
Traceback (most recent call last):
File "./SIML_LiverSeg/lib/hnet/test.py", line 16, in <module>
from scipy import ndimage
File "/Users/pictureme/venv/lib/python2.7/site-packages/scipy/ndimage/__init__.py", line 161, in <module>
from .filters import *
File "/Users/pictureme/venv/lib/python2.7/site-packages/scipy/ndimage/filters.py", line 36, in <module>
from . import _ni_support
ImportError: cannot import name _ni_support
The relevant parts of test.py (the beginning series of imports) are:
from __future__ import print_function
import sys
sys.path.insert(0,'./SIML_LiverSeg/lib/hnet/Keras-2.0.8')
from keras import backend as K
import os
import numpy as np
from medpy.io import load,save
from keras.optimizers import SGD
from hybridnet import dense_rnn_net
from loss import weighted_crossentropy
from lib.funcs import predict_tumor_inwindow
import argparse
from pathlib import Path
from scipy import ndimage
from skimage import measure
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
K.set_image_dim_ordering('tf') # Tensorflow dimension ordering in this code
The following is my $PATH that I set manually in MATLAB:
['./SIML_LiverSeg/lib/hnet/Keras-2.0.8', '/Users/pictureme/LiverSegApp/src/SIML_LiverSeg/lib/hnet', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Users/pictureme/venv/lib/python2.7/site-packages']
The scipy library is located in the last file directory. There is also a similar issue with the "from skimage import measure" line.
Additionally, if I do "from scipy import * ", this code works fine as well.
I would appreciate any help. This error seems strange. Thanks.
0 comentarios
Respuestas (0)
Ver también
Categorías
Más información sobre Call Python from MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!