从iron python脚本(从c脚本引擎调用)调用python脚本时出现问题

2024-05-17 08:46:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我在调用一个来自c#using的iron python脚本

        ScriptRuntimeSetup setup = Python.CreateRuntimeSetup(null);
        ScriptRuntime runtime = new ScriptRuntime(setup);
        ScriptEngine engine = Python.GetEngine(runtime);

        ScriptSource source = engine.CreateScriptSourceFromFile("C:/KitGenerator/KitGenerator/LoadKitsFromDatabase.py");
        ScriptScope scope = engine.CreateScope();
        source.Execute(scope);

这工作得很好,使用打印输出,我已经证明代码运行正确。 然而,在iron python脚本中是对另一个python脚本的调用

^{pr2}$

(我用just(ipython)试过了GenerateKitImages.py“)

问题是: 当我使用Ipy.exe文件两个都运行得很好,并按预期进行。 但是,当我使用c脚本引擎运行第一个iron python脚本时,它只运行第一个脚本,而不会调用第二个脚本。在

我在这件事上迷路了。我可以确认它与权限、依赖关系无关。在

一块金牌和一块披萨给能解决这个问题的人。在


Tags: py脚本sourcenewsetupnullengineruntime
1条回答
网友
1楼 · 发布于 2024-05-17 08:46:31

{raw>第一个调用

os.system(r"ipython C:\KitGenerator\Kit-Generator\GenerateKitImages.py")

否则反斜杠将导致问题。在

但是,既然你说它可以从ipy.exe文件,我猜第一种情况下ipython在你的{a1}上,而不是第二种情况。您可以设置路径environment variable from C#,在os.system调用中包含ipython的完整路径,或者通过changing it globally确保在调用C程序之前设置了路径。在

相关问题 更多 >