要将一些IronPython代码嵌入到C#中,我想使用ScriptEngine
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
Run Code Online (Sandbox Code Playgroud)
我找到了IronPython的参考资料,但是Scripting.Hosting的必要参考在哪里?我在VisualStudio 2008中找不到它,目标是.Net 3.5.
一直试图将这个IronPython程序编译成一个工作的.exe,过去3-4个小时没有运气.
我正在使用"IronPython 2.6 for .NET 4.0"附带的pyc.py
D:\IronTestCompile>ipy pyc.py file1.py file2.py /out:Program /main:program.py /target:exe
该程序编译为Program.dll和Program.exe但Program.exe无法运行.
我用它作为指南:
我开始工作的非常简单的'HelloWorld'程序,但是我的更复杂的程序失败了.我认为我的复杂程序无法按编译运行,因为它缺少DLL?
从IronPython目录中,我复制了编译所需的所有必需的DLL(Microsoft*.dll,IronPython*.dll)以及运行编译的HelloWorld.exe的运行时先决条件.
我怎么能弄清楚为什么我的.exe不能运行?或者,如何确定需要将哪些.NET DLL文件包含在目录中?(假设我必须将所有.NET DLL放在.exe目录示例中C:\WINDOWS\Microsoft.NET\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll -> D:\IronTestCompile?)
我在程序目录中唯一的DLL是:
Microsoft.Scripting.dll
IronPython.dll
IronPython.Modules.dll
Microsoft.Dynamic.dll
Run Code Online (Sandbox Code Playgroud)
我没有Microsoft.Scripting.Core.dll或Microsoft.Scripting.ExtensionAttribute.dll 导致我运行IronPython 2.6 for .NET 4.0
我应该有更多.dll吗?我的IronPython程序使用System.Windows.Forms以及其他一些...
谢谢你的帮助.
目标是编译这个程序并获取zip文件中的所有.DLL,以便我的兄弟可以解压缩并在他的comp上运行它,但截至目前我甚至无法在我自己的comp中运行它!有任何想法吗?
编辑:所以我弄清楚出了什么问题(请参阅下面的答案)但是现在我尝试在另一台计算机上运行应用程序时会得到这个可爱的弹出窗口:
Dang,现在我在尝试在另一台机器上运行app时遇到此错误.
要运行此应用程序,首先必须安装以下版本的.NET Framework之一:
v4.0.30319
不知道有没有办法解决这个问题.
编辑:我的修复是,我的兄弟有.NET 3.5所以我在另一台运行.NET 3.5的IronPython机器上重新编译它
我有以下IronPython代码.
class Hello:
def __init__(self):
pass
def add(self, x, y):
return (x+y)
Run Code Online (Sandbox Code Playgroud)
我需要从C#调用它,我想出了以下代码.
using System;
using IronPython.Hosting;
using IronPython.Runtime;
using IronPython;
using Microsoft.Scripting.Hosting;
using Microsoft.Scripting;
class Hello {
public static void Main()
{
ScriptEngine engine = Python.CreateEngine();
ScriptSource script = engine.CreateScriptFromSourceFile("myPythonScript.py");
ScriptScope scope = engine.CreateScope();
script.Execute(scope);
}
}
Run Code Online (Sandbox Code Playgroud)
复制IronPython.dll后,我运行以下命令.(我试图运行gacutil,但是我遇到了一些错误.
dmcs /r:IronPython.dll callipy.cs
但是我得到了一些错误消息,如下所示.
Could not load file or assembly 'Microsoft.Scripting.ExtensionAttribute, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Missing method .ctor in assembly /Users/smcho/Desktop/cs/namespace/IronPython.dll, type System.Runtime.CompilerServices.ExtensionAttribute Can't find …