Generate .NET Assemblies from Iron Python

做~自己de王妃 提交于 2019-12-03 08:43:45

问题


I have a Iron Python script that I want to run and then have the ipy interpreter output an assembly that I can run on other machines. How do I do that? Is there a switch I can pass to ipy.exe?


回答1:


There is a tool that ships with IronPython called Pyc or the Python Command-Line Compiler. If you installed the latest version 2.6 of IronPython, then pyc.py will be available at C:\Program Files (x86)\IronPython 2.6\Tools\Scripts or wherever you installed IronPython on your system. If you have earlier versions of IronPython then pyc.py will be available as a separate download in the samples package.

With pyc.py you can create console or Windows assemblies from your python scripts. Basic usage looks like this:

ipy pyc.py /out:myprogram.exe /main:mainfile.py /target:exe program.py support.py

The above will generate an assembly called myprogram.exe (/out) which is a console application (/target) and will execute the code in mainfile.py first (/main) and will also include code from program.py and support.py in the assembly.




回答2:


Using SharpDevelop

One way to is to use SharpDevelop, it builds assemblies (executables and class libraries) easily.

The process is straightforward:

  • Create a Python solution (Choices include: Class lib, Console or Windows application)
  • Write your Python code as normal
  • Build your solution or project

The .exe and .dll files will be in the relevant build output directory (Debug or Release).


Using pyc.py

Another way is to the IronPython command line compiler script called pyc.py.

The compiler script can be found in the directory: [IP_install_dir]\Tools\Scripts

Usage:
ipy.exe pyc.py /main:Program.py Form.py /target:winexe


Note: To get the compiled exe to run you will need the following files in the same directory as your executable:

IronPython.dll
IronPython.Modules.dll
Microsoft.Dynamic.dll
Microsoft.Scripting.Core.dll
Microsoft.Scripting.Debugging.dll
Microsoft.Scripting.dll
Microsoft.Scripting.ExtensionAttribute.dll



回答3:


you can also compile by using

import clr
clr.CompileModules("foo.dll","foo.py")

for asp.net, if you use pyc.py to compile, you wont be able to import the modules.They expect to fix that in 2.6.2 or later



来源:https://stackoverflow.com/questions/2437306/generate-net-assemblies-from-iron-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!