I'm trying to use one Python code in .NET using Ironpython, but a have problem with one imported library, How can I solve this Exception ?

When I try to execute de code returns this Exception: IronPython.Runtime.Exceptions.ImportException: 'No module named automata.fa.dfa'

Code Python:

class Automato:

def CalculaAutomato(self):

    from automata.fa.dfa import DFA

    dfa = DFA(states={'q0', 'q1', 'q2'},
        input_symbols={'0', '1'},
        transitions={
            'q0': {'0': 'q0', '1': 'q1'},
            'q1': {'0': 'q0', '1': 'q2'},
            'q2': {'0': 'q2', '1': 'q1'}
        },
        initial_state='q0',
        final_states={'q1'})

    if(dfa.accepts_input('01a10110')):
        print("accept")
        dfa.read_input('01a10110')
        #print(c)
    else:
        print('reject')

Python Project: Python Project Image

Code C#:

        var engine = Python.CreateEngine();
        ICollection<string> Paths = engine.GetSearchPaths();

        Paths.Add(@"C:\Users\dougl\source\repos\Automato\Automato\automata\base");
        Paths.Add(@"C:\Users\dougl\source\repos\Automato\Automato\automata\fa");
        Paths.Add(@"C:\Users\dougl\source\repos\Automato\Automato\automata\pda");
        Paths.Add(@"C:\Users\dougl\source\repos\Automato\Automato\automata\tm");

        engine.SetSearchPaths(Paths);

        dynamic py = engine.ExecuteFile(@"C:\Users\dougl\source\repos\Automato\Automato\Automato.py");
        dynamic automato = py.Automato();
        automato.CalculaAutomato();

i want the result in python appears in .NET to use with WinForms

0 Answers