For scriptcs, `dynamic` is not supported by Roslyn and is only available with mono, but mono crashes in the DLL

I am trying to load the pythonnet runtime dll from scripts and does not work with the roslyn backend, because the dynamics is not supported in Roslyn, but the mono backend suffocates with the following error:

$ 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 

Question:


How can I get mono-scripts of scripts working with Python.Runtime.DLL? Does DLL need to be loaded before? Should the Python.Runtime.DLL file compile with Mono or .NET support in order?

+6
source share
1 answer

This error (CS0009 with a monocompiler) is quite common and means "something is wrong" with this assembly, therefore it is rather difficult to debug. One way to continue is to really compile under mono. If you download the source code ( https://github.com/pythonnet ), you will find instructions on how to do this (look at pythonnet \ src \ monoclr \ README. Txt as well).

However, depending on your goals, you can instead use IronPython, which is officially supported mono and exhausted. The example below assumes that you downloaded the zip from IronPython and extracted it somewhere:

 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 > 
+4
source

All Articles