9

Can I compile an IronPython code to EXE or DLL in a .NET runtime?

Failed Scientist
  • 1,977
  • 3
  • 29
  • 48
Zippo
  • 15,850
  • 10
  • 60
  • 58
  • possible duplicate of [How do I create a .NET assembly in IronPython and call it from C#?](http://stackoverflow.com/questions/561509/how-do-i-create-a-net-assembly-in-ironpython-and-call-it-from-c) – Darin Dimitrov Nov 10 '10 at 18:21
  • 1
    The duplicate question is a year and a half old, and we have dynamic types in C# now. Let's keep this question open. – Robert Harvey Nov 10 '10 at 19:26

3 Answers3

6

Simply use clr.CompileModules in an IronPython script to convert it to a dll file. Or you can use pyc.py (found inside of your IronPythonInstallDirectory\Tools\Scripts) which can also generate an exe for you also.

Alastair McCormack
  • 26,573
  • 8
  • 77
  • 100
jcao219
  • 2,808
  • 3
  • 21
  • 22
  • After we obtained the dll how do we use it? ScriptEngine don't have an option to crate scope from dll. – ozgur Apr 30 '16 at 11:03
1

If I really, really needed that I would create a wrapper DLL/EXE in another language. The Python code can then be stored as a resource in the DLL that is loaded when the assembly is first accessed.

Jonathan Allen
  • 68,373
  • 70
  • 259
  • 447
0

Yes you can! I posted a Python script which can take an IronPython file, figure out its dependencies and compile the lot into a standalone binary at Ironpython 2.6 .py -> .exe. Hope you find it useful.

Community
  • 1
  • 1
Niall Douglas
  • 9,212
  • 2
  • 44
  • 54