Creating Windows Applications With Python

FINALLY! I’ve been looking all around for how people are creating working standalone applications in Windows using Python, and I do believe they are using Py2Exe. This is some pretty impressive stuff I think:

How does it work?

py2exe uses python’s modulefinder to examine your script and find all python and extension modules needed to run it. Pure python modules are compiled into .pyc or .pyo files in a temporary directory. Compiled extension modules (.pyd) are also found and parsed for binary dependencies.

A zip-compatible archive is built, containing all python files from this directory. Your main script is inserted as a resource into a custom embedded python interpreter supplied with py2exe, and the zip-archive is installed as the only item on sys.path.

In simple cases, only pythonxx.dll is needed in addition to myscript.exe. If, however, your script needs extension modules, unfortunately those cannot be included or imported from the zip-archive, so they are needed as separate files (and are copied into the dist directory).

Attention: py2exe tries to track down all binary dependencies for all pyd’s and dll’s copied to the dist directory recursively, and copies all these dependend files into the dist directory. py2exe has a builtin list of some system dlls which are not copied, but this list can never be complete.

I wish I’d stumbled across this earlier! I assumed I was going to have to munge around in Borland Delphi for a little pet project I’ve been considering, and bought a couple of books to learn more about it (since I’ve done some basic Pascal, but nothing past CLI apps). Delphi seemed to fit the bill for something which was compilable but didn’t have external dependencies on libraries, yet would not complicate things for a simple application like C++ would. Anyhow, it looks like I can skip that and go back to my favorite scriping language, Python, if I decide to end-up writing that particular tool.

Speaking of Borland, I wonder why they renamed themselves Inprise (forwards to, and then back to Borland? My guess would be that everyone still called them by Borland well after the name switch. Being a long time customer of theirs (I originally bought Borland Turbo C++ in the early 90′s from them in an attempt to learn it as an early teen without any other books.. that didn’t work out so well), I still find it silly that they even tried to switch from that name since it’s been around in the industry for quite some time.

And yes, it’s 3:20 AM on Sunday and I’m looking at geek stuff, but I’m on vacation dammit! I’m not too cool to admit that technology is my career as well as one of many personal hobbies.

This entry was posted in Languages, Tips, Hacks, & Tricks and tagged , , , , , , , , , , , . Bookmark the permalink.

Leave a reply