此错误(带有单编译器的 CS0009)非常通用,意味着给定程序集“有问题”,因此很难调试。一种方法确实是在单声道下编译。如果您下载他们的源代码 ( 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
>