2

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 Answer 1

2

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

For decompiling try:

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

1 Comment

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

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.