1

I'm completely new for both python and ironpython,help me to execute python scripts from c# without using ProcessStartInfo

My python Code.

import sys 

from PIL import Image

img = Image.open("c:\python27\Image.png")

img.show()

My C# Code is,

  var engine = Python.CreateEngine();
            var searchPaths = engine.GetSearchPaths();
            searchPaths.Add(@"C:\Python27\Lib");
            engine.SetSearchPaths(searchPaths);
            var scope = engine.CreateScope();
            ScriptSource source = engine.CreateScriptSourceFromFile(@"C:\Python27\Sample.py");

            source.Execute(scope);

when i run above code i'm getting Below Error.

An unhandled exception of type 'IronPython.Runtime.Exceptions.ImportException' occurred in Microsoft.Dynamic.dll

Additional information: No module named PIL.

udya
  • 157
  • 2
  • 15
  • Possible duplicate of [How do I run a Python script from C#?](https://stackoverflow.com/questions/11779143/how-do-i-run-a-python-script-from-c) – SᴇM Jun 22 '18 at 06:36
  • @seM,can you please check my post i mentioned without using "ProcessStartInfo".The Above code work fine when i use ProcessStartInfo.But it will not support PIL Module while i'm using ironpython C#. – udya Jun 22 '18 at 06:41
  • you can check other answers too, beside marked one. – SᴇM Jun 22 '18 at 06:43
  • Is this One :using IronPython.Hosting; using Microsoft.Scripting.Hosting; private static void doPython() { ScriptEngine engine = Python.CreateEngine(); engine.ExecuteFile(@"test.py"); } – udya Jun 22 '18 at 06:47
  • yes, that one is using same library. – SᴇM Jun 22 '18 at 06:48
  • i tried that one also, if python script contain only print statement only means like print("Hello") it will work. But i import library Like "from PIL import Image" i'm getting No module named PIL Error. – udya Jun 22 '18 at 06:52
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/173601/discussion-between-udya-and-sem). – udya Jun 22 '18 at 06:53

0 Answers0