IronPython sys._getframe not found
I'm currently building a program in C# which will call functions in provided python script files.
Some of these script files calls_getframe()
in sys
, which resul开发者_高级运维ts in the error:
System.MissingMemberException: 'module' object has no attribute '_getframe'
(Since IronPython doesn't have _getframe
activated by default.)
I have done quite a lot of googling and found out that you can activate it in ipy.exe
by providing -X:Frames
as a command line option, however this doesn't solve my problem since I'm not directly using ipy.exe
to execute the python code.
In this thread they mention rebuilding IronPython from source with the command line options, I downloaded the source files but have no idea how to build it with those options.
Also they mention that the options are in the official installer, I have run the installer exe several times but haven't seen a glimpse of those options there.When creating the PythonEngine you can pass a dictionary of options; you just need to set the "Frames" and/or "FullFrames" keys in the dictionary to true
:
var options = new Dictionary<string, object>();
options["Frames"] = true;
options["FullFrames"] = true;
ScriptEngine engine = Python.CreateEngine(options);
If you don't want FullFrames, just leave it out or set it to false
.
A little out of the scope of the question, but meant for anyone else getting this error by invoking a Python script using the ipy.exe interpreter directly.
You can just add the argument -X:FullFrames
. So for example invoke the script like
ipy.exe -X:FullFrames script.py
精彩评论