1

I have a function that executes a python script. The python script calls the jira library to connect to it's server. Then it will return data and will create an excel file for it. The python script is running ok when I executed manually, but the problem is when I call it on my asp function it returns error

there are no module name jira

I guess IronPython doesn't have library for jira because I just installed it on Python Library.

I even try to execute the script thru Process and it was triggered but unfortunately it doesn't return anything.

here is my code for executing a python thru IronPython

 ScriptRuntimeSetup setup = Python.CreateRuntimeSetup(null);
        ScriptRuntime runtime = new ScriptRuntime(setup);
        ScriptEngine engine = Python.GetEngine(runtime);
        var paths = engine.GetSearchPaths();
        paths.Add(@"C:\Users\jdecena\AppData\Local\Programs\Python\Python35\Lib");
        engine.SetSearchPaths(paths);
        ScriptSource source = engine.CreateScriptSourceFromFile("C:/Dave/jirautomatic/try.py");
        ScriptScope scope = engine.CreateScope();
        source.Execute(scope);
        dynamic Generate = scope.GetVariable("connect_to_jira_and_get_projects");
        dynamic gen = Generate();
        gen();

and here is my code executing python thru process

Process proc = new Process();
        proc.StartInfo.FileName = @"C:\Dave\jirautomatic\try.py";            
        proc.Start();
        proc.WaitForExit();
        proc.Dispose();

Is there a way that I can include the Library on Python to IronPython?

TIA

1 Answer 1

1

It is common problem when you are executing the python through c# or ASP.NET. Only the reason is C# expect all binaries in the form of assembly where python expects in the form of modules.

For this problem, two methods are available

Setting path in system variables

It is the simple is the simple way to set the modules into system variables. once the process started, then python will automatically search for the system path. either you can directly set the path in PATH variable or you can create new variable called PYTHONPATH

Setting path at runtime

This kind of approach is to set only for the life time of the application. for example, if any application want to use the 'known' module which are available in the project, then it can set the path runtime using sys module in python. But remember that once the program is executed, then the temporary variables will be lost. so this kind of code can be available either in c# or in python. use System.IO namespace in c# or sys module in Python

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, Can you give me example regarding this? Is GetSearchParth and SetSearchPath not enough?
Hi, this link might help you to set variable for your process link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.