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 siwtch I can pass to ipy.exe?
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
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.
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