【转载】C#调用python文件时出现'module' object has no attribute '_getframe'
2017-12-05 21:36
846 查看
这几天这个问题困扰了我很久;
任务需要,环境是在VS13.NET中安装了ironpython,可以调用python代码;
在不引用python第三方模块的时候,C#中调用python(.py文件)经测试是正常的;
但是现在需要调用第三方模块,查了一下解决办法是在.py文件中
import sys
sys.path.append(……) 如图是将python的第三方模块全部添加到环境里了,然后问题来了;
python代码本身经测试也没有问题
在C#窗体中调用代码如下,提源代码
运行是会报错:'module' object has no attribute '_getframe'
查了下python的sys模块,有_getframe
查了下ironpython的sys模块,没有_getframe
也不是很清楚怎么解决,听说有个参数是:-X:Frames要run,如图红框
但是也没有弄成功;
也有听说在interupter options里面加参数,但是也没用,求解决啊!!!!!!!
var options = new Dictionary<string, object>();
options["Frames"] = true;
options["FullFrames"] = true;
ScriptRuntime pyRunTime = Python.CreateRuntime(options);
ScriptScope pyScope = pyRunTime.CreateScope();
dynamic obj = pyRunTime.UseFile("ceshi.py");
如果你不想用FullFrames,把它设成false也可以。
更多
任务需要,环境是在VS13.NET中安装了ironpython,可以调用python代码;
在不引用python第三方模块的时候,C#中调用python(.py文件)经测试是正常的;
但是现在需要调用第三方模块,查了一下解决办法是在.py文件中
import sys
sys.path.append(……) 如图是将python的第三方模块全部添加到环境里了,然后问题来了;
python代码本身经测试也没有问题
在C#窗体中调用代码如下,提源代码
运行是会报错:'module' object has no attribute '_getframe'
查了下python的sys模块,有_getframe
查了下ironpython的sys模块,没有_getframe
也不是很清楚怎么解决,听说有个参数是:-X:Frames要run,如图红框
但是也没有弄成功;
也有听说在interupter options里面加参数,但是也没用,求解决啊!!!!!!!
var options = new Dictionary<string, object>();
options["Frames"] = true;
options["FullFrames"] = true;
ScriptRuntime pyRunTime = Python.CreateRuntime(options);
ScriptScope pyScope = pyRunTime.CreateScope();
dynamic obj = pyRunTime.UseFile("ceshi.py");
如果你不想用FullFrames,把它设成false也可以。
更多
相关文章推荐
- python运行不了 AttributeError: module object has no attribute getdefaultlocale
- 'module' object has no attribute 在python开发中出现的原因
- python 中出现的AttributeError: 'module' object has no attribute '_handlerList'
- 使用sae-python-dev本地运行web.py项目出现module object has no attribute InteractiveInterpreter
- 关于python里运行出现'module' object has no attribute 'xxxx'等问题解决方法
- python运行不了 AttributeError: module object has no attribute getdefaultlocale
- Python2.7 安装mock出现AttributeError: 'module' object has no attribute的解决方法
- 解决用easygui是出现Attribute: 'module' object has no attribute 'msgbox'
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’
- python AttributeError: 'module' object has no attribute 'dumps'解决办法
- web.py 启动时候出现AttributeError: 'module' object has no attribute 'inet_pton'错误
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- python django form error:module' object has no attribute '_meta'
- 'module' object has no attribute 'getppid' odoo openerp debug报错
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- [python错误]builtins.AttributeError: 'module' object has no attribute 'request'
- python 2.x和3.x关于 'module' object has no attribute 'open'的解决办法
- python遇到AttributeError: 'str' object has no attribute '_getAssertEqualityFunc'问题解决过程
- python大坑:AttributeError: 'module' object has no attribute 'Workbook'