我正在尝试使用IronPython运行c#代码。我创建了一个简单的控制台应用程序(.net 4),并添加了IronPython.dll、IronPython.Modules.dll和Microsoft.Scripting,并编写了下一个代码-
using Microsoft.Scripting.Hosting;
namespace app
{
class Program
{
static void Main(string[] args)
{
ScriptRuntime runtime = IronPython.Hosting.Python.CreateRuntime();
ScriptEngine engine = runtime.GetEngine("py");
engine.Execute("print 'hello!'");
}
}
}当我尝试运行这个的时候,我得到了一个例外-
未处理的异常: System.Reflection.TargetInvocationException:异常已被调用的目标抛出。-> System.IO.FileNotFoundException :无法加载文件或程序集'Microsoft.Scripting,Version=1.0.0.0,区域性=中性,PublicKeyToken=31bf3856ad364e35‘或其依赖项之一。系统找不到指定的文件。在System.RuntimeMethodHandle._InvokeConstructor(IRuntimeMethodInfo方法的Core.LanguageProvider.Python..ctor(流流)--内部异常堆栈跟踪的末端-- System.RuntimeMethodHandle.InvokeConstructor(IRuntimeMethodInfo方法的O bject[] args、SignatureStruct& SignatureStruct在CultureInfo System.Activator.CreateInstance(类型类型,BindingFlags bindingAttr,Binde r粘合剂,Object[] args,CultureInfo文化,Object[] activationAttributes)的System.Activator.CreateInstance(类型,类型)( Core.LanguageRuntime.RegisterLanguageProvider(Type providerType)在D:\cod e\CodeRunner\Core\LanguageRuntime.cs:line 30 at Test.Program.Main(String[] args)在D:\code\CodeRunner\Test\Program.cs:lin e 19按任意键继续。。。
我真的,t know what to do , searched at google and don找不到解决办法。我很乐意寻求帮助。
发布于 2011-03-08 20:04:22
你用的是哪个版本的铁蟒?您显示的语法似乎属于旧版本,现在您应该有如下内容:
var ipy = Python.CreateRuntime();无论如何,这篇博客文章在指出要使用的正确引用方面似乎是非常准确的。不管怎样,确保你有最新的IronPython版本。
https://stackoverflow.com/questions/5237431
复制相似问题