[IronPython] Can't start executable created with pyc.py

Bruce Bromberek bruce.bromberek at gmail.com
Thu Feb 25 05:53:20 CET 2010


There are differences between modules that the console (ipy.exe) loads
versus what is loaded when you compile.  When I build an exe I just go for
the kill and reference everything.  msscorlib, System, and System.Data are
key.

import sys
import clr

#Key IronPython References needed for final EXE when IronPython is not
installed
clr.AddReference('IronPython')
clr.AddReference('IronPython.Modules')
clr.AddReference('Microsoft.Dynamic')
clr.AddReference('Microsoft.Scripting')
clr.AddReference('Microsoft.Scripting.Core')
clr.AddReference('Microsoft.Scripting.Debugging')
clr.AddReference('Microsoft.Scripting.ExtensionAttribute')
clr.AddReference('mscorlib')
clr.AddReference('System')
clr.AddReference('System.Data')

#References to .NET Assemblies used by this program
clr.AddReference("System.Xml.Linq")
clr.AddReference("System.Xml")
clr.AddReference("System.Windows.Forms")
clr.AddReference("PresentationFramework, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35")
clr.AddReference("PresentationCore, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35")

#References to created DLL of python modules
clr.AddReference("StdLib")
clr.AddReference("ReportLab")





On Tue, Feb 23, 2010 at 6:17 AM, Neidhoo Xaphier <xaphiern at googlemail.com>wrote:

>
> Hello,
>
> I have a very simple python script I want to compile into an exe-File (with
> IronPython 2.6). The script is named "GuiTest.py":
>
> ### BEGIN GuiTest.py ###
> import clr
> clr.AddReference("PresentationFramework")
> clr.AddReference("PresentationCore")
>
> import System.Windows
> import System.Windows.Controls
>
> window        = System.Windows.Window()
> window.Title  = "GuiTest"
> window.Height = 200
> window.Width  = 450
>
> stack          = System.Windows.Controls.StackPanel()
> stack.Margin   = System.Windows.Thickness(15)
> window.Content = stack
>
> button = System.Windows.Controls.Button() button.Content = "Push Me!"
>
> def onClick(sender, event):
>     print "Button pushed!"
>
> button.Click += onClick
>
> stack.Children.Add(button)
>
> app = System.Windows.Application()
> app.Run(window)
> ### END GuiTest.py ###
>
> By using "pyc.py" I created "GuiTest.exe" with the following command line:
>
> ipy "C:\Programme\IronPython 2.6\Tools\Scripts\pyc.py" /main:GuiTest.py
> /target:exe
>
> Next I copied the following files into the same folder where GuiTest.exe is
> stored:
>
> IronPython.dll
> IronPython.Modules.dll
> Microsoft.Scripting.ExtensionAttribute.dll
> Microsoft.Dynamic.dll
> Microsoft.Scripting.Core.dll
> Microsoft.Scripting.Debugging.dll
> Microsoft.Scripting.dll
>
> Unfortunatelly GuiTest.exe still doesn't work. If I try to execute it from
> the command line I get the following error message:
>
> Unbehandelte Ausnahme: System.InvalidOperationException: Beim aufrufenden
> Thread muss es sich um einen STA-Thread handeln, da dies für viele
> Komponenten der Benutzeroberfläche erforderlich ist.
>    bei
> Microsoft.Scripting.Actions.Calls.MethodCandidate.Caller.Call(Object[] args,
> Boolean& shouldOptimize)
>    bei
> IronPython.Runtime.Types.BuiltinFunction.BuiltinFunctionCaller`6.Call5(Ca
> llSite site, CodeContext context, TFuncType func, T0 arg0, T1 arg1, T2 arg2,
> T3arg3, T4 arg4)
>    bei
> System.Dynamic.UpdateDelegates.UpdateAndExecute7[T0,T1,T2,T3,T4,T5,T6,TRet](CallSite
> site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
>    bei IronPython.Runtime.Importer.Import(CodeContext context, String
> fullName, PythonTuple from, Int32 level)
>    bei IronPython.Runtime.Operations.PythonOps.InitializeModule(Assembly
> precompiled, String main, String[] references)
>    bei PythonMain.Main()
>
> Do you have any ideas how I can resolve this issue?
>
> Best regards,
> Xaphier N.
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20100224/b994d4b8/attachment.html>


More information about the Ironpython-users mailing list