views:

31

answers:

1

we need to reference .py code from C#. This was solved using IronPython 2.6

The issue arises from the fact that .py code uses 'import customlib' which is a library compiled into customlib.pyc

IronPython gives error: IronPython.Runtime.Exceptions.ImportException: No module named customlib

attempted solution:

in python code add reference like this:

import sys
sys.path.append('c:\path to customlib')

that seems to work for other .py files but not for .pyc

Questions: 1) how do you reference .pyc in IronPython? 2) If its not possible, what are the alternatives to use .py and .pyc in C#.Net ? (obviously we don't have .py source code form customlib.pyc)

C# code that works for .py but not if .py imports .pyc:

ScriptEngine engine = Python.CreateEngine();
ScriptScope pyScope = null;
ScriptSource ss = null;
...
pyScope = engine.CreateScope();
ss = engine.CreateScriptSourceFromFile(@"C:\test.py");
ss.Execute(pyScope);
...
int result = (int)engine.Operations.InvokeMember(pyScope, "funcName")

thanks!

+1  A: 

*.pyc files are CPython specific. You'll have to decompile them or invoke CPython.

For decompiling try:

adw
thanks for suggestions.unpyc gave parsing error. online one doesn't seem to work at all.
jamesbt