    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: Silas's Corner</title>
        <link>https://members.accu.org/index.php/articles/816</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>




<div class="xar-mod-head"><span class="xar-mod-title">Programming Topics + CVu Journal Vol 17, #3 - Jun 2005</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c13/">Topics</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c65/">Programming</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c77/">CVu</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c96/">173</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/c65-96/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/articles/c65+96/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
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/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;Silas's Corner</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 02 June 2005 05:00:00 +01:00 or Thu, 02 June 2005 05:00:00 +01:00</p>
<p><strong>Summary:</strong>&nbsp;<h3>Cross-Compiling Python Scripts into Windows
Applications</h3>
</p>
<p><strong>Body:</strong>&nbsp;<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e24" id="d0e24"></a></h2>
</div>
<p>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.</p>
<p>py2exe (from <a href="http://py2exe.sourceforge.net" target=
"_top">py2exe.sourceforge.net</a>) 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.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e33" id="d0e33"></a>Cross-Compiling
from Another Operating System</h2>
</div>
<p>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.</p>
<p>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.</p>
<p>By default, py2exe creates a <tt class="filename">.exe</tt> 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 <tt class="filename">library.zip</tt>. So what you need
to do is get py2exe to compile a small &quot;wrapper&quot; module that
imports your main program from another module; that way, your main
module will also be stored in <tt class="filename">library.zip</tt>
where you can maintain it yourself without having to touch the
<tt class="filename">.exe</tt> file.</p>
<p>Put all the modules of your script into a directory on the
Windows system, and add a simple wrapper such as this:</p>
<pre class="programlisting">
# This is wrapper.py
import my_main_module
my_main_module.main()
</pre>
<p>Then add a suitable py2exe-compatible distutils setup script,
such as this:</p>
<pre class="programlisting">
# This is setup.py
from distutils.core import setup
import py2exe
setup(console=[&quot;wrapper.py&quot;])
</pre>
<p>Now type <tt class="literal">python setup.py py2exe</tt> and the
result will be put into the <tt class="filename">dist</tt>
subdirectory. Everything in that subdirectory goes onto your
distribution disc or whatever.</p>
<p>If you produce an updated version of <tt class=
"literal">my_main_module</tt>, compile it to Python bytecode
(<tt class="filename">my_main_module.pyc</tt>) and store it into
<tt class="filename">library.zip</tt>, replacing the previous
version (all other files in <tt class="filename">library.zip</tt>
stay the same). If your updated version requires extra library
modules, ensure that these (and any that they depend on) are also
present in <tt class="filename">library.zip</tt>, again in Python
bytecode format. It does not do any harm to put too many modules in
<tt class="filename">library.zip</tt>, 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.</p>
<p>During my tests, Py2exe stored the files in <tt class=
"filename">library.zip</tt> 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
<tt class="literal">-0</tt> to the command line.</p>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
