IronPython sys._getframe not found
Asked Answered
S

2

13

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 results 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.

Shortcircuit answered 9/8, 2011 at 14:30 Comment(0)
B
17

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.

Broz answered 9/8, 2011 at 16:40 Comment(0)
M
6

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
Malacostracan answered 28/1, 2015 at 20:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.