如何在 C# 2.0 中使用 –X:Frames 加载ironpython?

发布于 2024-09-07 05:28:53 字数 583 浏览 2 评论 0原文

我可以使用ironpython 2.6(不适用于.net 4)加载numpy,在命令行上使用 -X:Frames 或 -X:FullFrames 运行 ipy 。

但是,如果我想在 C# 2.0 中使用 Ironpython/DLR 加载 py 文件,如何使用 -X:Frames 或 -X:FullFrames ?

我这样尝试:

        var lang = Python.CreateLanguageSetup(null);
        lang.Options["Frames"] = ScriptingRuntimeHelpers.True;
        var setup = new ScriptRuntimeSetup();
        setup.LanguageSetups.Add(lang);
        var runtime = new ScriptRuntime(setup); 
        var engine = runtime.GetEngine("py");

        engine.ExecuteFile("test.py");  

但是,它不起作用! 那么,有人可以帮我吗?

I can use ironpython 2.6 (not for .net 4) load numpy, running ipy with -X:Frames or -X:FullFrames on the command line.

But, if I want to use Ironpython/DLR in C# 2.0 to load the py file, how can I use -X:Frames or -X:FullFrames?

I tried it like this:

        var lang = Python.CreateLanguageSetup(null);
        lang.Options["Frames"] = ScriptingRuntimeHelpers.True;
        var setup = new ScriptRuntimeSetup();
        setup.LanguageSetups.Add(lang);
        var runtime = new ScriptRuntime(setup); 
        var engine = runtime.GetEngine("py");

        engine.ExecuteFile("test.py");  

But, it didn't work!
So, is there anyone can give me a hand?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凹づ凸ル 2024-09-14 05:28:53

我不认为框架工作或不工作是你的问题。如果我将你的代码放入

import sys
sys._getframe()

test.py 中,如果我有 'lang.Options["Frames"] = ScriptingRuntimeHelpers.True;'如果我不这样做,就会失败。这表明该选项工作正常。

那么您遇到的错误是什么?您可能需要设置命令行通常执行的操作 - 例如 sys.path ,它可能需要当前目录和/或“.”。或者可能需要导入 site.py。或者,IronClad 可能安装在 DLL 目录中并自动加载,因此您需要对其 DLL 执行 runtime.LoadAssembly(...) 。

I don't think frames working or not working is your problem. If I take your code and put:

import sys
sys._getframe()

into test.py it works if I have the 'lang.Options["Frames"] = ScriptingRuntimeHelpers.True;' line and fails if I don't. That indicates the option is working fine.

So what is the error you're getting? It might be that you need to set something which the command line normally does - such as sys.path which maybe needs the current directory and/or ".". Or maybe site.py needs to be imported. Or maybe IronClad is installed in the DLLs directory and auto-loaded so you need to do runtime.LoadAssembly(...) on it's DLL.

电影里的梦 2024-09-14 05:28:53

您的问题看起来与此类似:
无法将 numpy 导入嵌入式 IronPython 引擎

但是,也许你应该提供有关您遇到的错误的更多信息...

Your question looks similar to this one:
Can't import numpy into embedded ironpython engine

But, maybe you should give more info about what errors you got...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文