[IronPython] Problems running simple executable compiled with the pyc.py tool

Dino Viehland dinov at microsoft.com
Fri May 6 13:51:30 PDT 2011


I see a couple of things going on here:
                The choice of wpf as your compiled name is unfortunate.  When we execute your "import wpf" is actually just bringing in your own module rather than bringing in the real wpf module.
                But even if you change the name it's still broken because we don't pick up the IronPython.Wpf.dll  which is in the DLLs directory of the IronPython install.

I'm not exactly sure what the best fix for the latter issue is -we probably need to try looking into the registry, seeing where IronPython is installed, and adding any references to the DLLs directory there for compiled apps.  Not sure if there's something better we could do though.

But you can work around it easily enough, you just need to add:

import clr
clr.AddReference('IronPython.Wpf')

before the import wpf and make sure that IronPython.Wpf.dll is in the same dir as your app (we don't GAC this DLL).

Then compiling with this command line worked for me:

"C:\Program Files (x86)\IronPython 2.7\ipy.exe" "C:\Program Files (x86)\IronPython 2.7\Tools\Scripts\pyc.py" /out:wpfx /main:wpfx.py wpfx.py /target:winexe

The way I debugged this was I compiled as a normal EXE so I could see the stack trace when things went wrong.  Once I got to this exception:

Unhandled Exception: System.InvalidOperationException: The calling thread must be STA, because many UI components require this.
   at System.Windows.Input.InputManager..ctor()
   at System.Windows.Input.InputManager.GetCurrentInputManagerImpl()
   at System.Windows.Input.KeyboardNavigation..ctor()
   at System.Windows.FrameworkElement.EnsureFrameworkServices()
   at System.Windows.FrameworkElement..ctor()
   at System.Windows.Controls.Control..ctor()
   at System.Windows.Window..ctor()

Then I switched back to compiling as a winexe.

The argument parsing in pyc.py definitely sucks, it should probably be switched to using a std lib arg parser.    Contributions are welcome if you'd like to improve any of this!

From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of iiyo cc
Sent: Friday, May 06, 2011 1:32 PM
To: Discussion of IronPython
Subject: Re: [IronPython] Problems running simple executable compiled with the pyc.py tool

Alright, I've come upon another problem, this time with using /target:winexe with a wpf type project. It seems to crash without any kind of error. I also noticed some curious things about the parameter order.
Here's the sample source I used to test: wpf.py and wpf.xaml -> http://codepad.org/XRLF8OSc

Compiling with:
"C:\Program Files (x86)\IronPython 2.7\ipy.exe" "C:\Program Files (x86)\IronPython 2.7\Tools\Scripts\pyc.py" /out:wpf /target:winexe /main:wpf.py wpf.py
For some reason, this will compile as a Console Application type

Changing the order:
"C:\Program Files (x86)\IronPython 2.7\ipy.exe" "C:\Program Files (x86)\IronPython 2.7\Tools\Scripts\pyc.py" /out:wpf  /main:wpf.py /target:winexe wpf.py
This compiles correctly, although it simply crashes on load.

Any ideas? Is it possible to compile if using wpf? I'm lost here - enjoying IronPython, but its distribution sure is hell.

On Fri, May 6, 2011 at 7:04 PM, Dino Viehland <dinov at microsoft.com<mailto:dinov at microsoft.com>> wrote:
Feel free to open a bug on supporting directories - it seems pretty reasonable to expect that to work.

From: users-bounces at lists.ironpython.com<mailto:users-bounces at lists.ironpython.com> [mailto:users-bounces at lists.ironpython.com<mailto:users-bounces at lists.ironpython.com>] On Behalf Of iiyo cc
Sent: Friday, May 06, 2011 11:02 AM
To: Discussion of IronPython
Subject: Re: [IronPython] Problems running simple executable compiled with the pyc.py tool

I followed your example, and it worked perfectly for me. I then realized it was my error all along - I assumed /out: could support directories (I had actually used /out:build\Program because of the batch file used to generate it), but this seems not to work in the way I'd imagined. Anyway, it's all working properly now.

Thanks, and apologies for the stupidity!
On Fri, May 6, 2011 at 6:12 PM, Dino Viehland <dinov at microsoft.com<mailto:dinov at microsoft.com>> wrote:
When running are Program.dll and Program.exe in the same location?  The reason I ask is that Program.exe will change the CWD to where it is currently located and then it'll attempt to load Program.dll from that directory.  That's the only thing that immediately comes to mind as having potential to break this for you.

Also, did you install IronPython via the MSI or by downloading the binary zip file?

I just tried this and it all seemed to work for me (I'm installed via the MSI so we can pick up the IronPython DLLs from the GAC):

C:\Users\dinov > type test.py
print('hi')
10:11:04.07
C:\Users\dinov > "C:\Program Files (x86)\IronPython 2.7\ipy.exe" "C:\Program Files (x86)\IronPython 2.7\Tools\Scripts\pyc.py" /target:exe /out:test /main:test.py test.py
Input Files:
        test.py
Output:
        test
Target:
        ConsoleApplication
Platform:
        ILOnly
Machine:
        I386
Compiling...
Saved to test

10:11:13.82
C:\Users\dinov > .\test.exe
hi


From: users-bounces at lists.ironpython.com<mailto:users-bounces at lists.ironpython.com> [mailto:users-bounces at lists.ironpython.com<mailto:users-bounces at lists.ironpython.com>] On Behalf Of iiyo cc
Sent: Friday, May 06, 2011 9:57 AM
To: users at lists.ironpython.com<mailto:users at lists.ironpython.com>
Subject: [IronPython] Problems running simple executable compiled with the pyc.py tool

Hello,

I keep coming up with the same problem when trying to run a compiled executable from the pyc.py tool. The error I'm getting is as follows:
Unhandled Exception: System.IO.FileNotFoundException: The system cannon find the file specified. (Exception from HRESULT: 0x80070002)
at System.Reflection.RuntimeAssembly.nLoadFile(String path, Evidence evidence)
at System.Reflection.Assembly.LoadFile(String path)
at PythonMain.Main()

My file is a simple Hello, World! program saved as Program.py with the following contents:
print 'Hello, World!'

I use the following command line to compile:
C:\IronPy\ipy C:\IronPy\Tools\Scripts\pyc.py Program.py /out:Program /main:Program.py /target:exe

Note: I'm using the latest 2.7 release through the IronPython installer on a Windows 7 64bit system, the executables are built (Program.dll and Program.exe) successfully, yet won't run even when sitting in the same directory as all the dlls one can find in the IronPython distribution. I've also tried targeting the x64 platform specifically with pyc, but to no avail. Here's what my working directory looks like when the project is built:
IronPython.dll, IronPython.Modules.dll, IronPython.Wpf.dll, Microsoft.Dynamic.dll, Microsoft.Scripting.dll, Microsoft.Scripting.Metadata.dll, Program.dll, Program.exe, Program.py

Hopefully someone knows what's going on, or if i'm doing something wrong.
Thanks.

_______________________________________________
Users mailing list
Users at lists.ironpython.com<mailto:Users at lists.ironpython.com>
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


_______________________________________________
Users mailing list
Users at lists.ironpython.com<mailto:Users at lists.ironpython.com>
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ironpython.com/pipermail/users-ironpython.com/attachments/20110506/8c00edb1/attachment-0001.htm>


More information about the Users mailing list