views:

101

answers:

2

Been trying to compile this IronPython program into a working .exe for the past 3-4 hours with no luck.

I'm using the pyc.py that came with "IronPython 2.6 for .NET 4.0"

D:\IronTestCompile>ipy pyc.py file1.py file2.py /out:Program /main:program.py /target:exe

The program compiles out to Program.dll & Program.exe but the Program.exe cannot run.

I'm using this as a guide:

IronPython - how to compile exe

The very simple 'HelloWorld' program I got to work, but my more complex program failed. I'm thinking my complex program failed to run as compiled becaues it's missing DLL's?

From IronPython directory I copied all the necessary DLL's (Microsoft*.dll, IronPython*.dll) that are needed for compilation and as run-time prerequisite to run compiled HelloWorld.exe.

How can I figure out why my .exe won't run? Or how do I determine what .NET DLL files are needed to be included in the directory? (Assuming I have to put all .NET DLL's in the .exe directory example C:\WINDOWS\Microsoft.NET\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll -> D:\IronTestCompile ? )

The only DLLs I have in the programs directory is:

Microsoft.Scripting.dll
IronPython.dll
IronPython.Modules.dll
Microsoft.Dynamic.dll

I do not have Microsoft.Scripting.Core.dll or Microsoft.Scripting.ExtensionAttribute.dll cause am running IronPython 2.6 for .NET 4.0

Should I have more .dll ? My IronPython program uses System.Windows.Forms as well as a bunch of others...

Thanks for any help.

Goal is to compile this program and get all .DLLs in zip file so my brother can unzip & run it on his comp, but as of now I can't even run it in my own comp! Any ideas?


EDIT: So I figured out what was wrong (see my answer below) But now I get this lovely pop-up when trying to run the app on another computer:

Dang, now I get this error when trying to run app on another machine.


MyApp.exe - .NET Framework Initialization Error

To run this application, you first must install one of the following versions of the .NET Framework:

v4.0.30319

Contact your application publisher for instructions about obtaining the appropriate version of the .NET Framework.

OK

Wonder if there's any way to get around this.

EDIT: My fix was, my bro had .NET 3.5 so I re-compiled it on a different machine that had IronPython running .NET 3.5

A: 

Have you checked that target machine have .NET Framework 4.0 installed?

Migol
Yes, it wouldn't even run on my own machine. So when I just `ipy.exe program.py` it runs fine, but the compiled `program.exe` version from the pyc.py doesn't run (crashes and pops up visual studio debugger)
Quang
Maybe you could provide informations from this crash? Is it .NET exception or some other error?
Migol
It says "An unhandled win32 exception occurred in Program.exe[4048]."
Quang
I'm going through my code line by line (commenting out) and it seems that when I init a System.Windows.Forms.WebBrowser() it causes a 'ThreadStateException' error i think. Weird I wonder how come `ipy.exe program.py` causes no errors yet when I compile it, it does.
Quang
Looks like compiler bug. Report it.
Migol
+3  A: 

Yes, it successfully compiled an ran.

Reason being was I had uncaught exceptions in my source.

For some reason the lines

import traceback
import inspect

Caused the IronPython Compiler to throw an "ImportError", but ipy.exe Program.py runs fine.

Also the biggest bug was a "ThreadStateException" error (Thanks Migol for the tip) when I tried to init System.Windows.Forms.WebBrowser()

Googled it, and found out that:

Oh, the problem is that pyc.py doesn't mark the thread as STA.

And the fix is:

You can add this line to pyc.py right after mainMethod = ...

mainMethod.SetCustomAttribute(clr.GetClrType(System.STAThreadAttribute).GetConstructor(()), System.Array[System.Byte](()))

source: http://www.mail-archive.com/[email protected]/msg07725.html

Sweet. :)

Works, compiles and runs, Turns out the only DLLs you need for "IronPython 2.6 for .NET 4.0" are

IronPython.dll
IronPython.Modules.dll
Microsoft.Scripting.dll
Microsoft.Dynamic.dll
Mycrosoft.Scripting.Debugging.dll

(Just copy & paste these from your C:\Program Files\IronPython 2.6 for .NET 4.0\ directory or wherever you installed IronPython)

Also the exact command I used to compile my script is:

D:\IronTestCompile\project_3>"c:\Program Files\IronPython 2.6 for .NET 4.0\ipy.exe" pyc.py Form1.py utils.py project.py /out:MyApp /main:program.py /target:winexe

follow this guide IronPython - how to compile exe

turns out you only have to include the files that you import in your main: file (mine was program.py. PYC.py takes care of importing the rest. :)

edit: Actually you would add all .py you want to compile to the pyc.py command. If you don't compile it (It'll be combined into MyApp.dll) you can keep the .py in the App's directory and it'll still run, but then this exposes it's source.

Hope this helps somebody, took me one whole evening to figure it out. Cheers. =)

Quang
Thank you for taking the time to explain that - very good to know.
schmoopy