0

So I am having some troubles importing Pyro or Pyro4 while using IronPython as a C# ScriptEngine.

The import works fine if run directly in the ipy interpreter, but I receive the following error when ipy is initialized as a script engine from a c# script.

TypeErrorException: sequence item 0: expected bytes or byte array, str found
IronPython.Runtime.Operations.ByteOps.AppendJoin (System.Object value, Int32  index, System.Collections.Generic.List`1 byteList)
IronPython.Runtime.Bytes.join (System.Object sequence)
Microsoft.Scripting.Interpreter.FuncCallInstruction`3[IronPython.Runtime.Bytes,System.Object,IronPython.Runtime.Bytes].Run (Microsoft.Scripting.Interpreter.InterpretedFrame frame)
Microsoft.Scripting.Interpreter.Interpreter.Run    (Microsoft.Scripting.Interpreter.InterpretedFrame frame)

I am passing the -X:FullFrames and -X:Frames parameters to ipy at it's initialization already, so I believe I have ruled that out. In fact, this error happens whether or not I initialize with this parameters.

Here is my code in c#:

// Set the fullframes parameter in a dict
var options = new Dictionary<string, object>();
options["Frames"] = true;
options["FullFrames"] = true;
// create the engine  
var ScriptEngine = IronPython.Hosting.Python.CreateEngine(options);
// and the scope (ie, the python namespace)  
var ScriptScope = ScriptEngine.CreateScope();

//set the python file to execute
string scriptPath = "Assets\\test.py";
var ScriptSource = ScriptEngine.CreateScriptSourceFromFile(scriptPath);

And, of course, in the python script, I am receiving this error upon import of Pyro.

import Pyro

This error is typically obtuse for working with IPY, and I am stumped. Any insight at all, including any techniques to get a little more traceback would be of great help.

Thanks in advance!

FuzzkingCool
  • 309
  • 4
  • 14
  • I have one clue which is that in IronPython, strings are unicode, which may be the root of the issue. But this still doesn't explain why this code will run in the standard ipy.exe but not in the ScriptEngine. – FuzzkingCool Mar 22 '17 at 00:08

1 Answers1

0

The issue was I was using dlls from IPY 2.7.4 and the site-lib modules for 2.7.7.

One step further, and I discovered that 2.7.4 has issues with Pyro as described here:

http://pyro-core.narkive.com/0G88Usma/bug-typeerror-expected-pointer-got-int64

If you can see your full traceback from IPY, you can see the line in Pyro that causes the issue, and a hacky fix is to comment out the method.

FuzzkingCool
  • 309
  • 4
  • 14
  • 1
    What are you using Ironpython for? Are you running other python code as well? If you're only using the Pyro _client_ functionality from your C# environment, you can also choose to use the Pyrolite native .NET library instead (https://pythonhosted.org/Pyro4/pyrolite.html) – Irmen de Jong Mar 22 '17 at 21:01