Browse in : |
All
> Topics
> Programming
All > Journals > CVu > 173 Any of these categories - All of these categories |
Note: when you create a new publication type, the articles module will automatically use the templates user-display-[publicationtype].xt and user-summary-[publicationtype].xt. If those templates do not exist when you try to preview or display a new article, you'll get this warning :-) Please place your own templates in themes/yourtheme/modules/articles . The templates will get the extension .xt there.
Title: Silas's Corner
Author: Administrator
Date: 02 June 2005 05:00:00 +01:00 or Thu, 02 June 2005 05:00:00 +01:00
Summary:
Cross-Compiling Python Scripts into Windows Applications
Body:
I recently wanted to distribute my Python program to a few other people who were running Windows computers and who were not technically minded. Asking them to go through the process of installing a Python interpreter on their systems was not an option.
py2exe (from py2exe.sourceforge.net) is a fairly simple approach to converting Python into standalone Windows programs. Py2exe installation will modify an existing Windows Python installation, but both Python and py2exe let you install without administrator privileges, so if you have user access to a Windows system then you can install both in a temporary directory.
Py2exe only runs on Windows, so if your usual operating system is not Windows then you will have to move to Windows every time you want to release a new version of your program, which is not ideal. I wanted to find a way of making a Windows standalone executable without using Windows to do it.
The Windows emulator WINE is not yet up to the task. However, if you can get to a Windows system to run py2exe once, you can do it in such a way that incrementally maintaining the result is possible.
By default, py2exe creates a .exe file that contains your main module, but all other Python modules (whether supplied by you or part of the library) are put into a file called library.zip. So what you need to do is get py2exe to compile a small "wrapper" module that imports your main program from another module; that way, your main module will also be stored in library.zip where you can maintain it yourself without having to touch the .exe file.
Put all the modules of your script into a directory on the Windows system, and add a simple wrapper such as this:
# This is wrapper.py import my_main_module my_main_module.main()
Then add a suitable py2exe-compatible distutils setup script, such as this:
# This is setup.py from distutils.core import setup import py2exe setup(console=["wrapper.py"])
Now type python setup.py py2exe and the result will be put into the dist subdirectory. Everything in that subdirectory goes onto your distribution disc or whatever.
If you produce an updated version of my_main_module, compile it to Python bytecode (my_main_module.pyc) and store it into library.zip, replacing the previous version (all other files in library.zip stay the same). If your updated version requires extra library modules, ensure that these (and any that they depend on) are also present in library.zip, again in Python bytecode format. It does not do any harm to put too many modules in library.zip, except that it will be larger than necessary. If additional binary modules (e.g. C or C++ modules) are required then this is more complicated; in that case it is better if you had imported them in the initial code when you ran py2exe on Windows.
During my tests, Py2exe stored the files in library.zip with no compression. I'm not sure if it will always work so well if you use compression. Most zip utilities can be told to avoid compression; for example, Info-Zip, distributed with many Linux systems, will do this if you add -0 to the command line.
Notes:
More fields may be available via dynamicdata ..