ironpython this_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 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.

回答1:

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();

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.

回答2:

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

来源:https://stackoverflow.com/questions/6997832/ironpython-sys-getframe-not-found

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值