我尝试从scriptcs加载pythonnet运行时dll,但是它不适用于Roslyn后端,因为roslyn不支持dynamic,但是mono后端阻塞了以下错误:
$ scriptcs -modules mono
scriptcs (ctrl-c to exit or :help for help)
> #r "F:\Python\Python27\Lib\site-packages\Python.Runtime.dll"
error CS0009: Metadata file `F:\Python\Python27\Lib\site-packages\Python.Runtime.dll' does not contain valid metadata问题:
如何让脚本的Mono后端与Python.Runtime.DLL一起工作?在此之前,我需要加载任何DLL吗?Python.Runtime.DLL必须用Mono支持编译,还是.NET很好?
发布于 2015-09-12 17:57:17
此错误(带有mono编译器的CS0009)相当通用,对给定的程序集意味着“出了问题”,因此很难调试。进行操作的一种方法确实是在mono下编译。如果您下载了他们的源代码(https://github.com/pythonnet),您会发现关于如何做到这一点的说明(也可以查看pythonnet\src\monoclr\README.txt )。
但是,根据您的目标,您可以考虑使用IronPython,这是由mono正式支持的,并且已经用完了。下面的示例假设您下载了IronPython的zip并在某个地方解压它:
scriptcs -modules mono
scriptcs (ctrl-c to exit or :help for help)
> #r "G:\dev_tools\IronPython-2.7.5\IronPython-2.7.5\IronPython.dll"
> #r "G:\dev_tools\IronPython-2.7.5\IronPython-2.7.5\Microsoft.Dynamic.dll"
> #r "G:\dev_tools\IronPython-2.7.5\IronPython-2.7.5\Microsoft.Scripting.dll"
> using System;
> using System.IO;
> using IronPython.Hosting;
> using Microsoft.Scripting;
> using Microsoft.Scripting;
> using Microsoft.Scripting.Hosting;
> string script = "print 'hello world'";
> var engine = Python.CreateEngine();
> var scope = engine.CreateScope();
> var source = engine.CreateScriptSourceFromString(script, SourceCodeKind.Statements);
> var compiled = source.Compile();
> var result = compiled.Execute(scope);
hello world
>https://stackoverflow.com/questions/32471727
复制相似问题