tags:

views:

37

answers:

1

I am trying to call a python script from a windows executable, ultimately the goal is a windows service that I can plug various scripts into, for example to pull back email attachments (since python has good imap support). Of course, I am a total newb so I am clueless :) I get an unhandled exception:

System.NotImplementedException: The method or operation is not implemented. at Microsoft.Scripting.PlatformAdaptationLayer.OpenInputFileStream(String path)

and gobs more but that seems to be the key issue. Clearly this must have to do with reading the code from a file because the simple change below makes it work. I'm wondering if this is a bug in IP 2.7A1 but I think I would have found that in my hopefully exhaustive web search. Okay, here's the code:

var engine = Python.CreateEngine();
var script = engine.CreateScriptSourceFromFile("PyTest.py");
ScriptScope scope = engine.CreateScope();
script.Execute(scope);

and the PyTest.py code is very simple, an example from the web:

import sys

#def Main():

def adder(arg1, arg2):
        return arg1 + arg2

class MyClass(object):
        def __init__(self, value):
            self.value = value

if I call that script by assigning it to a string value and using the CreateScriptSourceFromString method it works fine. I have verified that the code can see the PyTest.py file by doing a file.exists(fileName) and it sees the file. I also tried explicitly giving the path to no avail.

Thanks for any suggestions!

A: 

Are you sure you're using a build of IronPython which is for the .NET framework? The Silverlight builds (which will also load on the desktop framework) have filesystem stuff disabled. I can do this from a console .exe just fine, so please provide some more information.

Jimmy Schementi
You may be on to it, I did have to get the dlls from the Silverlight folder which bugged me a bit, that would explain it. I have the 2.71A release from http://ironpython.codeplex.com/releases/view/42434 In the installer options I see bins under Silverlight but not under tools for VS.
VinceGeek
In Alpha 1 we only installed the binaries into the GAC. You can find those below %WINDIR%\Microsoft.NET\assembly. In 2.7B1 we now include the files in the install dir as well so it's more convenient to find them.
Dino Viehland
YES!!!! thanks very much, that was the problem, also got rid of my mysterious warning. Excellent!
VinceGeek