开发者

IronPython -> .exe Executable & distribute with all DLLs HELP

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开发者_如何学Go: 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


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/users@lists.ironpython.com/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. =)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜