<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Mouse Vs. The Python &#187; Linux</title>
	<atom:link href="http://www.blog.pythonlibrary.org/category/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.blog.pythonlibrary.org</link>
	<description>Python Programming from the Frontlines</description>
	<lastBuildDate>Sun, 08 Jan 2012 12:45:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>A bbfreeze Tutorial &#8211; Build a Binary Series!</title>
		<link>http://www.blog.pythonlibrary.org/2010/08/19/a-bbfreeze-tutorial-build-a-binary-series/</link>
		<comments>http://www.blog.pythonlibrary.org/2010/08/19/a-bbfreeze-tutorial-build-a-binary-series/#comments</comments>
		<pubDate>Thu, 19 Aug 2010 13:23:23 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Packaging]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[bbfreeze]]></category>
		<category><![CDATA[binaries]]></category>
		<category><![CDATA[Cross-Platform]]></category>
		<category><![CDATA[Distribution]]></category>

		<guid isPermaLink="false">http://www.blog.pythonlibrary.org/?p=1137</guid>
		<description><![CDATA[The bbfreeze package also allows us to create binaries, but only on Linux and Windows. It&#8217;s just an easy_install away, so if you plan on following along with the examples in the article, you should go get it. The bbfreeze package includes egg support, so it can include egg dependencies in your binary, unlike py2exe. [...]]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:left;"><div class="socialize-in-button socialize-in-button-left"><a href="http://twitter.com/share" class="twitter-share-button" data-counturl="http://www.blog.pythonlibrary.org/2010/08/19/a-bbfreeze-tutorial-build-a-binary-series/" data-url="http://bit.ly/t6R0h2" data-text="A bbfreeze Tutorial &#8211; Build a Binary Series!" data-count="vertical" data-via="socializeWP" ><!--Tweetter--></a></div><div class="socialize-in-button socialize-in-button-left"><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.blog.pythonlibrary.org/2010/08/19/a-bbfreeze-tutorial-build-a-binary-series/&amp;layout=button_count&amp;show_faces=true&amp;width=100&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px !important; height:65px;" allowTransparency="true"></iframe></div><div class="socialize-in-button socialize-in-button-left"><script type="text/javascript">
			<!-- 
			reddit_url = "http://www.blog.pythonlibrary.org/2010/08/19/a-bbfreeze-tutorial-build-a-binary-series/";
			reddit_title = "A bbfreeze Tutorial &#8211; Build a Binary Series!";	//-->
		</script><script type="text/javascript" src="http://www.reddit.com/static/button/button2.js"></script></div><div class="socialize-in-button socialize-in-button-left"><g:plusone size="small" href="http://www.blog.pythonlibrary.org/2010/08/19/a-bbfreeze-tutorial-build-a-binary-series/"></g:plusone></div></div><p>The bbfreeze package also allows us to create binaries, but only on Linux and Windows. It&#8217;s just an easy_install away, so if you plan on following along with the examples in the article, you should go get it. The bbfreeze package includes egg support, so it can include egg dependencies in your binary, unlike py2exe. You can also freeze multiple scripts at once, include the Python interpreter and more. According to bbfreeze&#8217;s PyPI entry, it&#8217;s only been tested with Python 2.4-2.5, so keep that in mind. However, I was able to use it with Python 2.6 with no obvious problems.<span id="more-1137"></span></p>
<h2>Getting Started with bbfreeze</h2>
<p>You can use easy_install to download and install bbfreeze or you can just download its source or the egg file directly from the <a href="http://pypi.python.org/pypi/bbfreeze/">Python Package Index</a> (PyPI). In this article, we&#8217;ll try using it on a simple configuration file generator script and we&#8217;ll also try it against a lame wxPython program. My test machine was a Windows 7 Home Edition 32-bit laptop with bbfreeze 0.96.5, and Python 2.6.4. Let&#8217;s start with the configuration script:</p>
<pre class="python"><span style="color: #808080; font-style: italic;"># config_1.py</span>
<span style="color: #ff7700;font-weight:bold;">import</span> configobj
&nbsp;
<span style="color: #808080; font-style: italic;">#----------------------------------------------------------------------</span>
<span style="color: #ff7700;font-weight:bold;">def</span> createConfig<span style="color: black;">&#40;</span>configFile<span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;
    Create the configuration file
    &quot;</span><span style="color: #483d8b;">&quot;&quot;</span>
    config = configobj.<span style="color: black;">ConfigObj</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    inifile = configFile
    config.<span style="color: black;">filename</span> = inifile
    config<span style="color: black;">&#91;</span><span style="color: #483d8b;">'server'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">&quot;http://www.google.com&quot;</span>
    config<span style="color: black;">&#91;</span><span style="color: #483d8b;">'username'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">&quot;mike&quot;</span>
    config<span style="color: black;">&#91;</span><span style="color: #483d8b;">'password'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">&quot;dingbat&quot;</span>
    config<span style="color: black;">&#91;</span><span style="color: #483d8b;">'update interval'</span><span style="color: black;">&#93;</span> = <span style="color: #ff4500;">2</span>
    config.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#----------------------------------------------------------------------</span>
<span style="color: #ff7700;font-weight:bold;">def</span> getConfig<span style="color: black;">&#40;</span>configFile<span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;
    Open the config file and return a configobj
    &quot;</span><span style="color: #483d8b;">&quot;&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> configobj.<span style="color: black;">ConfigObj</span><span style="color: black;">&#40;</span>configFile<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> createConfig2<span style="color: black;">&#40;</span>path<span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;
    Create a config file
    &quot;</span><span style="color: #483d8b;">&quot;&quot;</span>
    config = configobj.<span style="color: black;">ConfigObj</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    config.<span style="color: black;">filename</span> = path
    config<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Sony&quot;</span><span style="color: black;">&#93;</span> = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>
    config<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Sony&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;product&quot;</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">&quot;Sony PS3&quot;</span>
    config<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Sony&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;accessories&quot;</span><span style="color: black;">&#93;</span> = <span style="color: black;">&#91;</span><span style="color: #483d8b;">'controller'</span>, <span style="color: #483d8b;">'eye'</span>, <span style="color: #483d8b;">'memory stick'</span><span style="color: black;">&#93;</span>
    config<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Sony&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;retail price&quot;</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">&quot;$400&quot;</span>
    config.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
    createConfig2<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;sampleConfig2.ini&quot;</span><span style="color: black;">&#41;</span></pre>
<p>This script has a couple of functions that are pointless, but we&#8217;ll leave them in for illustrative purposes. According to the bbfreeze documentation, we should be able to create a binary with the following string typed into the command line:</p>
<p><code><br />
bb-freeze config_1.py<br />
</code></p>
<p>This assumes that you have &#8220;C:\Python26\Scripts&#8221; on your path. If you don&#8217;t, you&#8217;ll need to type the complete path out (i.e. &#8220;C:\Python26\Scripts\bb-freeze config_1.py&#8221;). When I ran this, I got an error. Here it is:</p>
<pre class="python">Traceback <span style="color: black;">&#40;</span>most recent call last<span style="color: black;">&#41;</span>:
  File <span style="color: #483d8b;">&quot;C:<span style="color: #000099; font-weight: bold;">\P</span>ython26<span style="color: #000099; font-weight: bold;">\S</span>cripts<span style="color: #000099; font-weight: bold;">\b</span>b-freeze-script.py&quot;</span>, line <span style="color: #ff4500;">8</span>, <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #66cc66;">&lt;</span>module<span style="color: #66cc66;">&gt;</span>
    load_entry_point<span style="color: black;">&#40;</span><span style="color: #483d8b;">'bbfreeze==0.96.5'</span>, <span style="color: #483d8b;">'console_scripts'</span>, <span style="color: #483d8b;">'bb-freeze'</span><span style="color: black;">&#41;</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
  File <span style="color: #483d8b;">&quot;C:<span style="color: #000099; font-weight: bold;">\P</span>ython26<span style="color: #000099; font-weight: bold;">\l</span>ib<span style="color: #000099; font-weight: bold;">\s</span>ite-packages<span style="color: #000099; font-weight: bold;">\b</span>bfreeze-0.96.5-py2.6-win32.egg<span style="color: #000099; font-weight: bold;">\b</span>bfreeze<span style="color: #000099; font-weight: bold;">\_</span>_init__.py&quot;</span>, line <span style="color: #ff4500;">18</span>, <span style="color: #ff7700;font-weight:bold;">in</span> main
    f<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
  File <span style="color: #483d8b;">&quot;C:<span style="color: #000099; font-weight: bold;">\P</span>ython26<span style="color: #000099; font-weight: bold;">\l</span>ib<span style="color: #000099; font-weight: bold;">\s</span>ite-packages<span style="color: #000099; font-weight: bold;">\b</span>bfreeze-0.96.5-py2.6-win32.egg<span style="color: #000099; font-weight: bold;">\b</span>bfreeze<span style="color: #000099; font-weight: bold;">\f</span>reezer.py&quot;</span>, line <span style="color: #ff4500;">474</span>, <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #0000cd;">__call__</span>
    <span style="color: #008000;">self</span>.<span style="color: black;">addModule</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;encodings.*&quot;</span><span style="color: black;">&#41;</span>
  File <span style="color: #483d8b;">&quot;C:<span style="color: #000099; font-weight: bold;">\P</span>ython26<span style="color: #000099; font-weight: bold;">\l</span>ib<span style="color: #000099; font-weight: bold;">\s</span>ite-packages<span style="color: #000099; font-weight: bold;">\b</span>bfreeze-0.96.5-py2.6-win32.egg<span style="color: #000099; font-weight: bold;">\b</span>bfreeze<span style="color: #000099; font-weight: bold;">\f</span>reezer.py&quot;</span>, line <span style="color: #ff4500;">411</span>, <span style="color: #ff7700;font-weight:bold;">in</span> addModule
    <span style="color: #008000;">self</span>.<span style="color: black;">mf</span>.<span style="color: black;">import_hook</span><span style="color: black;">&#40;</span>name<span style="color: black;">&#91;</span>:<span style="color: #ff4500;">-2</span><span style="color: black;">&#93;</span>, fromlist=<span style="color: #483d8b;">&quot;*&quot;</span><span style="color: black;">&#41;</span>
  File <span style="color: #483d8b;">&quot;C:<span style="color: #000099; font-weight: bold;">\P</span>ython26<span style="color: #000099; font-weight: bold;">\l</span>ib<span style="color: #000099; font-weight: bold;">\s</span>ite-packages<span style="color: #000099; font-weight: bold;">\b</span>bfreeze-0.96.5-py2.6-win32.egg<span style="color: #000099; font-weight: bold;">\b</span>bfreeze<span style="color: #000099; font-weight: bold;">\m</span>odulegraph<span style="color: #000099; font-weight: bold;">\m</span>odulegraph.py&quot;</span>, line <span style="color: #ff4500;">256</span>, <span style="color: #ff7700;font-weight:bold;">in</span> import_hook
    modules.<span style="color: black;">update</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">ensure_fromlist</span><span style="color: black;">&#40;</span>m, fromlist<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
  File <span style="color: #483d8b;">&quot;C:<span style="color: #000099; font-weight: bold;">\P</span>ython26<span style="color: #000099; font-weight: bold;">\l</span>ib<span style="color: #000099; font-weight: bold;">\s</span>ite-packages<span style="color: #000099; font-weight: bold;">\b</span>bfreeze-0.96.5-py2.6-win32.egg<span style="color: #000099; font-weight: bold;">\b</span>bfreeze<span style="color: #000099; font-weight: bold;">\m</span>odulegraph<span style="color: #000099; font-weight: bold;">\m</span>odulegraph.py&quot;</span>, line <span style="color: #ff4500;">345</span>, <span style="color: #ff7700;font-weight:bold;">in</span> ensure_fromlist
    fromlist.<span style="color: black;">update</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">find_all_submodules</span><span style="color: black;">&#40;</span>m<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
  File <span style="color: #483d8b;">&quot;C:<span style="color: #000099; font-weight: bold;">\P</span>ython26<span style="color: #000099; font-weight: bold;">\l</span>ib<span style="color: #000099; font-weight: bold;">\s</span>ite-packages<span style="color: #000099; font-weight: bold;">\b</span>bfreeze-0.96.5-py2.6-win32.egg<span style="color: #000099; font-weight: bold;">\b</span>bfreeze<span style="color: #000099; font-weight: bold;">\m</span>odulegraph<span style="color: #000099; font-weight: bold;">\m</span>odulegraph.py&quot;</span>, line <span style="color: #ff4500;">369</span>, <span style="color: #ff7700;font-weight:bold;">in</span> find_all_submodules
    <span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: black;">&#40;</span>path, mode, typ<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">in</span> ifilter<span style="color: black;">&#40;</span><span style="color: #008000;">None</span>, imap<span style="color: black;">&#40;</span>moduleInfoForPath, names<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:
<span style="color: #008000;">NameError</span>: <span style="color: #ff7700;font-weight:bold;">global</span> name <span style="color: #483d8b;">'ifilter'</span> <span style="color: #ff7700;font-weight:bold;">is</span> <span style="color: #ff7700;font-weight:bold;">not</span> defined</pre>
<p>It would seem that the &#8220;modulegraph.py&#8221; file is missing an import from the <a href="http://docs.python.org/library/itertools.html">itertools</a> library, which is included with Python. I edited my copy of &#8220;modulegraph.py&#8221; to include the following line at the top of the file: &#8220;from itertools import ifilter&#8221;. This got rid of that traceback, but it raised another because &#8220;imap&#8221; wasn&#8217;t defined either. To fix the second error, I changed my import to &#8220;from itertools import ifilter,imap&#8221; and then it ran with no problems and produced a binary in a &#8220;dist&#8221; folder along with nine other files (see screenshot below).</p>
<p><a href="http://www.blog.pythonlibrary.org/wp-content/uploads/2010/08/bbfreeze_dir.png"><img src="http://www.blog.pythonlibrary.org/wp-content/uploads/2010/08/bbfreeze_dir.png" alt="bbfreeze_dir.png" title="bbfreeze_dir.png" width="599" height="324" class="aligncenter size-full wp-image-1148" /></a></p>
<h2>Using bbfreeze&#8217;s Advanced Configuration</h2>
<p>The PyPI page for bbfreeze (which is also its home page) has very little documentation. However, the page does say that the preferred way to use bbfreeze is with little scripts. We&#8217;re going to try using creating a binary with the lame wxPython, mentioned earlier. Here&#8217;s the wx code:</p>
<pre class="python"><span style="color: #ff7700;font-weight:bold;">import</span> wx
&nbsp;
<span style="color: #808080; font-style: italic;">########################################################################</span>
<span style="color: #ff7700;font-weight:bold;">class</span> DemoPanel<span style="color: black;">&#40;</span>wx.<span style="color: black;">Panel</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;&quot;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">#----------------------------------------------------------------------</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, parent<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;Constructor&quot;</span><span style="color: #483d8b;">&quot;&quot;</span>
        wx.<span style="color: black;">Panel</span>.<span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, parent<span style="color: black;">&#41;</span>
&nbsp;
        labels = <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Name&quot;</span>, <span style="color: #483d8b;">&quot;Address&quot;</span>, <span style="color: #483d8b;">&quot;City&quot;</span>, <span style="color: #483d8b;">&quot;State&quot;</span>, <span style="color: #483d8b;">&quot;Zip&quot;</span>,
                  <span style="color: #483d8b;">&quot;Phone&quot;</span>, <span style="color: #483d8b;">&quot;Email&quot;</span>, <span style="color: #483d8b;">&quot;Notes&quot;</span><span style="color: black;">&#93;</span>
&nbsp;
        mainSizer = wx.<span style="color: black;">BoxSizer</span><span style="color: black;">&#40;</span>wx.<span style="color: black;">VERTICAL</span><span style="color: black;">&#41;</span>
        lbl = wx.<span style="color: black;">StaticText</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, label=<span style="color: #483d8b;">&quot;Please enter your information here:&quot;</span><span style="color: black;">&#41;</span>
        lbl.<span style="color: black;">SetFont</span><span style="color: black;">&#40;</span>wx.<span style="color: black;">Font</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">12</span>, wx.<span style="color: black;">SWISS</span>, wx.<span style="color: black;">NORMAL</span>, wx.<span style="color: black;">BOLD</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        mainSizer.<span style="color: black;">Add</span><span style="color: black;">&#40;</span>lbl, <span style="color: #ff4500;">0</span>, wx.<span style="color: black;">ALL</span>, <span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">for</span> lbl <span style="color: #ff7700;font-weight:bold;">in</span> labels:
            sizer = <span style="color: #008000;">self</span>.<span style="color: black;">buildControls</span><span style="color: black;">&#40;</span>lbl<span style="color: black;">&#41;</span>
            mainSizer.<span style="color: black;">Add</span><span style="color: black;">&#40;</span>sizer, <span style="color: #ff4500;">1</span>, wx.<span style="color: black;">EXPAND</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">SetSizer</span><span style="color: black;">&#40;</span>mainSizer<span style="color: black;">&#41;</span>
        mainSizer.<span style="color: black;">Layout</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">#----------------------------------------------------------------------</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> buildControls<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, label<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;&quot;</span>
        sizer = wx.<span style="color: black;">BoxSizer</span><span style="color: black;">&#40;</span>wx.<span style="color: black;">HORIZONTAL</span><span style="color: black;">&#41;</span>
        size = <span style="color: black;">&#40;</span><span style="color: #ff4500;">80</span>,<span style="color: #ff4500;">40</span><span style="color: black;">&#41;</span>
        font = wx.<span style="color: black;">Font</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">12</span>, wx.<span style="color: black;">SWISS</span>, wx.<span style="color: black;">NORMAL</span>, wx.<span style="color: black;">BOLD</span><span style="color: black;">&#41;</span>
&nbsp;
        lbl = wx.<span style="color: black;">StaticText</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, label=label, size=size<span style="color: black;">&#41;</span>
        lbl.<span style="color: black;">SetFont</span><span style="color: black;">&#40;</span>font<span style="color: black;">&#41;</span>
        sizer.<span style="color: black;">Add</span><span style="color: black;">&#40;</span>lbl, <span style="color: #ff4500;">0</span>, wx.<span style="color: black;">ALL</span>|wx.<span style="color: black;">CENTER</span>, <span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> label <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">&quot;Notes&quot;</span>:
            txt = wx.<span style="color: black;">TextCtrl</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, name=label<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
            txt = wx.<span style="color: black;">TextCtrl</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, style=wx.<span style="color: black;">TE_MULTILINE</span>, name=label<span style="color: black;">&#41;</span>
        sizer.<span style="color: black;">Add</span><span style="color: black;">&#40;</span>txt, <span style="color: #ff4500;">1</span>, wx.<span style="color: black;">ALL</span>, <span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> sizer
&nbsp;
&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;">########################################################################</span>
<span style="color: #ff7700;font-weight:bold;">class</span> DemoFrame<span style="color: black;">&#40;</span>wx.<span style="color: black;">Frame</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;
    Frame that holds all other widgets
    &quot;</span><span style="color: #483d8b;">&quot;&quot;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">#----------------------------------------------------------------------</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;Constructor&quot;</span><span style="color: #483d8b;">&quot;&quot;</span>
        wx.<span style="color: black;">Frame</span>.<span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, <span style="color: #008000;">None</span>, wx.<span style="color: black;">ID_ANY</span>,
                          <span style="color: #483d8b;">&quot;cxFreeze Tutorial&quot;</span>,
                          size=<span style="color: black;">&#40;</span><span style="color: #ff4500;">600</span>,<span style="color: #ff4500;">400</span><span style="color: black;">&#41;</span>
                          <span style="color: black;">&#41;</span>
        panel = DemoPanel<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">Show</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#----------------------------------------------------------------------</span>
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
    app = wx.<span style="color: black;">App</span><span style="color: black;">&#40;</span><span style="color: #008000;">False</span><span style="color: black;">&#41;</span>
    frame = DemoFrame<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    app.<span style="color: black;">MainLoop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre>
<p>Now let&#8217;s create a simple freezing script!</p>
<pre class="python"><span style="color: #808080; font-style: italic;"># bb_setup.py</span>
<span style="color: #ff7700;font-weight:bold;">from</span> bbfreeze <span style="color: #ff7700;font-weight:bold;">import</span> Freezer
&nbsp;
f = Freezer<span style="color: black;">&#40;</span>distdir=<span style="color: #483d8b;">&quot;bb-binary&quot;</span><span style="color: black;">&#41;</span>
f.<span style="color: black;">addScript</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;sampleApp.py&quot;</span><span style="color: black;">&#41;</span>
f<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre>
<p>First off, we import the <em>Freezer</em> class from the bbfreeze package. Freezer accepts three arguments: a destination folder, an includes iterable and an excludes iterable (i.e. a tuple or list). Just to see how well bbfreeze works with only its defaults, we leave out the includes and excludes tuples/lists. Once you have a Freezer object, you can add your script(s) by calling the Freezer object name&#8217;s <em>addScript</em> method. Then you just need to call the object (i.e.  f() ). If you do all that, you should end up with a 14.5 MB folder holding 18 files. When I ran the sampleApp.exe file, it ran just fine and was properly themed, however it also had a console screen. To figure out the correct syntax, I used <a href="http://code.google.com/p/gui2exe/">GUI2Exe</a>. Here&#8217;s the new code:</p>
<pre class="python"><span style="color: #808080; font-style: italic;"># bb_setup2.py</span>
<span style="color: #ff7700;font-weight:bold;">from</span> bbfreeze <span style="color: #ff7700;font-weight:bold;">import</span> Freezer
&nbsp;
includes = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
excludes = <span style="color: black;">&#91;</span><span style="color: #483d8b;">'_gtkagg'</span>, <span style="color: #483d8b;">'_tkagg'</span>, <span style="color: #483d8b;">'bsddb'</span>, <span style="color: #483d8b;">'curses'</span>, <span style="color: #483d8b;">'email'</span>, <span style="color: #483d8b;">'pywin.debugger'</span>,
            <span style="color: #483d8b;">'pywin.debugger.dbgcon'</span>, <span style="color: #483d8b;">'pywin.dialogs'</span>, <span style="color: #483d8b;">'tcl'</span>,
            <span style="color: #483d8b;">'Tkconstants'</span>, <span style="color: #483d8b;">'Tkinter'</span><span style="color: black;">&#93;</span>
&nbsp;
bbFreeze_Class = Freezer<span style="color: black;">&#40;</span><span style="color: #483d8b;">'dist'</span>, includes=includes, excludes=excludes<span style="color: black;">&#41;</span>
&nbsp;
bbFreeze_Class.<span style="color: black;">addScript</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;sampleApp.py&quot;</span>, gui_only=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
&nbsp;
bbFreeze_Class.<span style="color: black;">use_compression</span> = <span style="color: #ff4500;">0</span>
bbFreeze_Class.<span style="color: black;">include_py</span> = <span style="color: #008000;">True</span>
bbFreeze_Class<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre>
<p>If you run this, you should end up with a &#8220;dist&#8221; folder that contains 18 files and is 16.6 MB in size. Notice that we added a second argument to the <em>addScript</em> method: gui_only=True. This makes that annoying console go away. We also set compression to zero (no compression, I think) and include the Python interpreter. Turning on compression only reduced the result down to 14.3 MB though. </p>
<p>The bbfreeze package also handles &#8220;recipes&#8221; and includes several examples, however they are not documented well either and I couldn&#8217;t figure out how to include them with my current examples. Feel free to figure them out on your own!</p>
<h2>Wrapping Up</h2>
<p>Well, now you should know the basics of using bbfreeze to create binaries from your programs. I hope you found this helpful. The last article in this series will be on GUI2Exe. Look for it soon!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.pythonlibrary.org/2010/08/19/a-bbfreeze-tutorial-build-a-binary-series/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python Text-to-Speech: Making Your PC Talk</title>
		<link>http://www.blog.pythonlibrary.org/2010/04/02/python-test-to-speech-making-your-pc-talk/</link>
		<comments>http://www.blog.pythonlibrary.org/2010/04/02/python-test-to-speech-making-your-pc-talk/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 22:57:13 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.blog.pythonlibrary.org/?p=751</guid>
		<description><![CDATA[Soon after getting hired at my current job, my boss sent me a script (which I think was based on this article) about Python and a certain text-to-speech module called pyTTS. This was right after Python 2.5 had released. Anyway, it&#8217;s basically a nice wrapper over the win32com module which can communicate with the Microsoft [...]]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:left;"><div class="socialize-in-button socialize-in-button-left"><a href="http://twitter.com/share" class="twitter-share-button" data-counturl="http://www.blog.pythonlibrary.org/2010/04/02/python-test-to-speech-making-your-pc-talk/" data-url="http://bit.ly/vtj84K" data-text="Python Text-to-Speech: Making Your PC Talk" data-count="vertical" data-via="socializeWP" ><!--Tweetter--></a></div><div class="socialize-in-button socialize-in-button-left"><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.blog.pythonlibrary.org/2010/04/02/python-test-to-speech-making-your-pc-talk/&amp;layout=button_count&amp;show_faces=true&amp;width=100&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px !important; height:65px;" allowTransparency="true"></iframe></div><div class="socialize-in-button socialize-in-button-left"><script type="text/javascript">
			<!-- 
			reddit_url = "http://www.blog.pythonlibrary.org/2010/04/02/python-test-to-speech-making-your-pc-talk/";
			reddit_title = "Python Text-to-Speech: Making Your PC Talk";	//-->
		</script><script type="text/javascript" src="http://www.reddit.com/static/button/button2.js"></script></div><div class="socialize-in-button socialize-in-button-left"><g:plusone size="small" href="http://www.blog.pythonlibrary.org/2010/04/02/python-test-to-speech-making-your-pc-talk/"></g:plusone></div></div><p>Soon after getting hired at my current job, my boss sent me a script (which I think was based on this <a href="http://mindtrove.info/articles/synthesizing-speech-with-pytts/">article</a>) about Python and a certain text-to-speech module called <a href="http://www.cs.unc.edu/Research/assist/doc/pytts/">pyTTS</a>. This was right after Python 2.5 had released. Anyway, it&#8217;s basically a nice wrapper over the win32com module which can communicate with the Microsoft Speech API (SAPI).<span id="more-751"></span></p>
<p>I won&#8217;t go over everything about pyTTS since that article I linked to above already does that, but I will give you a quick introduction to it. If you go to the author&#8217;s <a href="http://mindtrove.info/clique/">website</a> you&#8217;ll find that he&#8217;s moved on to Screen Reading technology and has created a program called Clique. I&#8217;m not sure if that is written in Python or not though. I went digging on the site to find out where you could download the software and finally found this: <a href="http://sourceforge.net/projects/uncassist/files/ ">http://sourceforge.net/projects/uncassist/files/ </a></p>
<p>From what I can tell, he only officially support Python 2.3-2.5. However, since pyTTS basically just wraps the win32com calls to SAPI and the PyWin32 module supports Python 2.x-3.x, I think it would be fairly easy to make pyTTS work with the newer versions. </p>
<p><em>Note: You will need the <a href="http://www.cs.unc.edu/Research/assist/packages/SAPI5SpeechInstaller.msi">Microsoft SAPI 5.1 redistributable</a>, <a href="http://www.cs.unc.edu/Research/assist/packages/SAPI5VoiceInstaller.msi">extra MS voices</a> and <a href="http://sourceforge.net/projects/pywin32/files/">PyWin32</a>.</em></p>
<p>Let&#8217;s take a quick look at how we use this module:</p>
<pre class="python"><span style="color: #ff7700;font-weight:bold;">import</span> pyTTS
tts = pyTTS.<span style="color: black;">Create</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
tts.<span style="color: black;">SetVoiceByName</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'MSSam'</span><span style="color: black;">&#41;</span>
tts.<span style="color: black;">Speak</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Hello, fellow Python programmer&quot;</span><span style="color: black;">&#41;</span></pre>
<p>You don&#8217;t have to set the voice as I think the default it MSMary, but it&#8217;s fun to do. The Speak method accepts various flags for its second argument. One example is pyTTS.tts_async, which puts the speaking in asynchronous mode. You can also mess with the volume by doing this: tts.Volume = 50. You can choose anywhere from 0-100%.</p>
<p>If you look at this <a href="http://mindtrove.info/articles/synthesizing-speech-with-pytts/">article</a>, it will teach you how to make pyTTS pronounce the words you feed it.</p>
<p>Here is how you would do most of the example above using PyWin32:</p>
<pre class="python"><span style="color: #ff7700;font-weight:bold;">from</span> win32com.<span style="color: black;">client</span> <span style="color: #ff7700;font-weight:bold;">import</span> constants
<span style="color: #ff7700;font-weight:bold;">import</span> win32com.<span style="color: black;">client</span>
speaker = win32com.<span style="color: black;">client</span>.<span style="color: black;">Dispatch</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;SAPI.SpVoice&quot;</span>, constants.<span style="color: black;">SVSFlagsAsync</span><span style="color: black;">&#41;</span>
speaker.<span style="color: black;">Speak</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Hello, fellow Python programmer&quot;</span><span style="color: black;">&#41;</span></pre>
<p>While researching this article, I noticed that the developer(s) behind pyTTS had also put together a cross-platform text-to-speech module called <a href="http://pypi.python.org/pypi/pyttsx">pyttsx</a>. I haven&#8217;t used it, but I encourage you to give it a try. Other modules worth a look are <a href="http://code.google.com/p/pyspeech/">pySpeech</a> and this cool recipe that allows Python to recognize speech: <a href="http://www.surguy.net/articles/speechrecognition.xml">http://www.surguy.net/articles/speechrecognition.xml</a></p>
<p>Well, this ended up being more of a survey of the cool speech-related modules in Python than about code. Still, I hope this will prove helpful to you in your endeavors.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.pythonlibrary.org/2010/04/02/python-test-to-speech-making-your-pc-talk/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 1.354 seconds -->

