Using Python to call MATLAB scripts in different directories results in Undefined function 'x'' for input arguments of type 'int64'

Currently I am building a testing framework that uses MATLAB and Python scripts. I have one main script say 'MainFramework.py' that calls and passes arguments to a Class say 'MainClass_X.py' that calls and passes arguments to a function say 'x.py' that itself calls and passes arguments to 'x.m'.
the MainFramework.py has the following format of code:
from MainClass_X import MainClass_X
arg1="something1"
arg2="something2"
Test=MainClass_X(arg1,arg2)
Test.run()
the MainClass_X.py has the following format of code:
from x import x
class MainClass_X(object):
def __init__(self,paramater1,parameter2):
self.paramater1=paramater1
self.paramater2=paramater2
def run(self):
x(self.paramater1,self.paramater2)
the function x.py has the following format of code:
import matlab.engine
def x(arg1,arg2):
eng=matlab.engine.start_matlab()
eng.x(arg1,arg2,nargout=0)
When MainFramework.py, MainClass_X.py, x.py and x.m scripts are all in the same directory the scripts work as designed. However, as soon as I move MainFramework.py into a parent directory, the script gives me the following MATLAB error: Undefined function 'x'' for input arguments of type 'int64'.
For better understanding, please find below the structure of the directories:
__directory1__
MainFramework.py
__directory1/subdirectory1__
MainClass_X.py
x.py
x.m
I have double checked the path to make sure that MainFramework.py calls on the right MainClass_X.py, and I am sure that it does.
I am using MATLAB 2020a and Python 3.7 and Anaconda3 and Spyder as an IDLE.
Is there any way to get around this error. It is very important for the purpose of the task that the python scripts are in different directories.

1 commentaire

Please let me know if you need the solution if you are facing this problem as I find a solution. it involes eng.addpath();

Connectez-vous pour commenter.

Réponses (0)

Catégories

Produits

Version

R2020b

Commenté :

le 22 Oct 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by