<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Mariano Guerra's Log (Posts about exe)</title><link>http://marianoguerra.org/</link><description></description><atom:link href="http://marianoguerra.org/categories/exe.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><lastBuildDate>Mon, 18 Nov 2024 17:56:44 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>[EN] How to generate .exe files and installers for a python (and pygtk) applications</title><link>http://marianoguerra.org/posts/201010en-how-to-generate-exe-files-and/</link><dc:creator>Mariano Guerra</dc:creator><description>&lt;div class="document" id="how-to-generate-exe-files-and-installers-for-a-python-applications"&gt;&lt;h1 class="title"&gt;How to generate .exe files and installers for a python applications&lt;/h1&gt;&lt;br&gt;&lt;p&gt;This document describes the steps required to create an executable file from a&lt;br&gt;python program and how to build an installer and portable file from that&lt;br&gt;application.&lt;/p&gt;&lt;br&gt;&lt;p&gt;The document assumes that the application is based on GTK but it should work&lt;br&gt;with minor changes for other toolkits.&lt;/p&gt;&lt;div class="section" id="why-an-installer"&gt;&lt;h1&gt;why an installer&lt;/h1&gt;&lt;ul class="simple"&gt;&lt;li&gt;many components are required to install by hand by the end user for a simple application&lt;/li&gt;&lt;li&gt;a lot of small installers&lt;/li&gt;&lt;li&gt;hard to find&lt;/li&gt;&lt;li&gt;hard to match the exact versions that work together&lt;/li&gt;&lt;li&gt;install them in the required order&lt;/li&gt;&lt;li&gt;pray&lt;/li&gt; &lt;li&gt;sometimes even doing everything right it may not work&lt;/li&gt;&lt;li&gt;easy to automate and document to replicate with each new version&lt;/li&gt;&lt;li&gt;free the end user from problems to use the app&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div class="section" id="required-components"&gt;&lt;h1&gt;required components&lt;/h1&gt;&lt;ul class="simple"&gt;&lt;li&gt;python&lt;/li&gt;&lt;li&gt;all the libraries used by the application&lt;/li&gt;&lt;li&gt;py2exe&lt;/li&gt; &lt;li&gt;nsis&lt;/li&gt;&lt;li&gt;time and luck ;)&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div class="section" id="installers"&gt;&lt;h1&gt;installers&lt;/h1&gt;&lt;p&gt;here are listed the links to the installers of all the components used in the example.&lt;/p&gt;&lt;ul class="simple"&gt;&lt;li&gt;&lt;a class="reference external" href="http://python.org/ftp/python/2.6.6/python-2.6.6.msi"&gt;http://python.org/ftp/python/2.6.6/python-2.6.6.msi&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="reference external" href="http://sourceforge.net/projects/py2exe/files/py2exe/0.6.9/py2exe-0.6.9.win32-py2.6.exe/download"&gt;http://sourceforge.net/projects/py2exe/files/py2exe/0.6.9/py2exe-0.6.9.win32-py2.6.exe/download&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="reference external" href="http://ftp.gnome.org/pub/GNOME/binaries/win32/pycairo/1.8/pycairo-1.8.6.win32-py2.6.exe"&gt;http://ftp.gnome.org/pub/GNOME/binaries/win32/pycairo/1.8/pycairo-1.8.6.win32-py2.6.exe&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a class="reference external" href="http://ftp.gnome.org/pub/GNOME/binaries/win32/pygobject/2.20/pygobject-2.20.0.win32-py2.6.exe"&gt;http://ftp.gnome.org/pub/GNOME/binaries/win32/pygobject/2.20/pygobject-2.20.0.win32-py2.6.exe&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="reference external" href="http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/2.16/pygtk-2.16.0+glade.win32-py2.6.exe"&gt;http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/2.16/pygtk-2.16.0+glade.win32-py2.6.exe&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="reference external" href="http://sourceforge.net/projects/pywin32/files/pywin32/Build%20214/pywin32-214.win32-py2.6.exe/download"&gt;http://sourceforge.net/projects/pywin32/files/pywin32/Build%20214/pywin32-214.win32-py2.6.exe/download&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="reference external" href="http://sourceforge.net/projects/gtk-win/files/GTK%2B%20Runtime%20Environment/GTK%2B%202.22/gtk2-runtime-2.22.0-2010-10-01-ash.exe/download"&gt;http://sourceforge.net/projects/gtk-win/files/GTK%2B%20Runtime%20Environment/GTK%2B%202.22/gtk2-runtime-2.22.0-2010-10-01-ash.exe/download&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="reference external" href="http://sourceforge.net/projects/gtk-win/files/GTK%2B%20Themes%20Package/2009-09-07/gtk2-themes-2009-09-07-ash.exe/download"&gt;http://sourceforge.net/projects/gtk-win/files/GTK%2B%20Themes%20Package/2009-09-07/gtk2-themes-2009-09-07-ash.exe/download&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="reference external" href="http://prdownloads.sourceforge.net/nsis/nsis-2.46-setup.exe?download"&gt;http://prdownloads.sourceforge.net/nsis/nsis-2.46-setup.exe?download&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div class="section" id="installation-order"&gt;&lt;h1&gt;installation order&lt;/h1&gt;&lt;br&gt;&lt;p&gt;some installers are independent from the others, but to avoid posible problems I recommend the installation in this order.&lt;/p&gt;&lt;ul class="simple"&gt;&lt;li&gt;python&lt;/li&gt;&lt;li&gt;gtk-runtime&lt;/li&gt;&lt;li&gt;gtk2-themes&lt;/li&gt;&lt;li&gt;nsis&lt;/li&gt;&lt;li&gt;pygobject&lt;/li&gt;&lt;li&gt;pycairo&lt;/li&gt;&lt;li&gt;pygtk&lt;/li&gt; &lt;li&gt;pywin32&lt;/li&gt;&lt;li&gt;py2exe&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div class="section" id="extra-tasks"&gt;&lt;h1&gt;extra tasks&lt;/h1&gt;&lt;ul class="simple"&gt;&lt;li&gt;set the PATH environment variable to add the path to the python installation&lt;/li&gt;&lt;li&gt;test that the installation works with a simple gtk application&lt;/li&gt;&lt;/ul&gt;&lt;pre class="literal-block"&gt;&amp;gt;&amp;gt;&amp;gt; import gtk&lt;br&gt;&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; w = gtk.Window()&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; l = gtk.Label("asd")&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; w.add(l)&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; w.show_all()&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; gtk.main()&lt;br&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="section" id="test-with-a-sample-application"&gt;&lt;h1&gt;test with a sample application&lt;/h1&gt;&lt;br&gt;&lt;p&gt;I created a repository with a sample application to test the steps, the application is available in github here:&lt;/p&gt;&lt;p&gt;&lt;a class="reference external" href="http://github.com/marianoguerra/PyGtkOnWindows"&gt;http://github.com/marianoguerra/PyGtkOnWindows&lt;/a&gt;&lt;/p&gt;&lt;div class="section" id="steps"&gt;&lt;h2&gt;steps&lt;/h2&gt;&lt;ul class="simple"&gt;&lt;li&gt;download it&lt;/li&gt;&lt;li&gt;unpack it&lt;/li&gt;&lt;li&gt;run python setup.py py2exe&lt;/li&gt;&lt;li&gt;copy the lib and share directory from the gtk runtime installation  (not the pygtk installation) to the dist directory&lt;/li&gt;&lt;li&gt;copy all the files from the dll directory to the dist directory&lt;/li&gt; &lt;li&gt;remove unused locales and unused themes (I keep only ms theme)&lt;/li&gt;&lt;li&gt;create the following dirs inside dist: etc/gtk-2.0&lt;/li&gt;&lt;li&gt;inside that create a file called gtkrc with a line like this inside:&lt;ul&gt;&lt;li&gt;gtk-theme-name = "MS-Windows"&lt;/li&gt;&lt;li&gt;you can change the theme by keeping that theme inside share/themes and changing the name in gtkrc&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;right click on ejemplo.nsi and select "Compile NSIS Script"&lt;/li&gt;&lt;li&gt;right click on ejemplo-portable.nsi and select "Compile NSIS Script"&lt;/li&gt; &lt;li&gt;you should have the installer and portable versions available&lt;/li&gt;&lt;li&gt;to test that it works correctly, run the installer and portable versions in a windows installation without the packages you installed previously&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="section" id="test-with-a-real-application"&gt;&lt;h1&gt;test with a real application&lt;/h1&gt;&lt;p&gt;now to make it feel more real let's create an installer and portable versions&lt;br&gt;for a real world program, in this case, a project of mine called emesene 2&lt;br&gt;(&lt;a class="reference external" href="http://www.emesene.org/"&gt;http://www.emesene.org/&lt;/a&gt;).&lt;/p&gt;&lt;div class="section" id="id1"&gt;&lt;h2&gt;steps&lt;/h2&gt;&lt;br&gt;&lt;ul class="simple"&gt;&lt;li&gt;download it from &lt;a class="reference external" href="http://github.com/emesene/emesene"&gt;http://github.com/emesene/emesene&lt;/a&gt;&lt;/li&gt;&lt;li&gt;unpack it&lt;/li&gt;&lt;li&gt;copy setup.py and ez_setup.py to the emesene directory&lt;/li&gt;&lt;li&gt;cd to emesene&lt;/li&gt;&lt;li&gt;run python setup.py py2exe&lt;/li&gt;&lt;li&gt;cd ..&lt;/li&gt;&lt;li&gt;copy the lib and share directory from the gtk runtime installation  (not the pygtk installation) to the dist directory&lt;/li&gt;&lt;li&gt;copy all the files from the dll directory to the dist directory&lt;/li&gt; &lt;li&gt;remove unused locales and unused themes (I keep only ms theme)&lt;/li&gt;&lt;li&gt;create the following dirs inside dist: etc/gtk-2.0&lt;/li&gt;&lt;li&gt;inside that create a file called gtkrc with a line like this inside:&lt;ul&gt;&lt;li&gt;gtk-theme-name = "MS-Windows"&lt;/li&gt;&lt;li&gt;you can change the theme by keeping that theme inside share/themes and changing the name in gtkrc&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;right click on emesene.nsi and select "Compile NSIS Script"&lt;/li&gt;&lt;li&gt;right click on emesene-portable.nsi and select "Compile NSIS Script"&lt;/li&gt; &lt;li&gt;you should have the installer and portable versions available&lt;/li&gt;&lt;li&gt;to test that it works correctly, run the installer and portable versions in a windows installation without the packages you installed previously&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="section" id="notes"&gt;&lt;h1&gt;notes&lt;/h1&gt;&lt;ul class="simple"&gt;&lt;li&gt;I get some needed dlls from portable python (&lt;a class="reference external" href="http://www.portablepython.com/"&gt;http://www.portablepython.com/&lt;/a&gt;) and inkscape (&lt;a class="reference external" href="http://inkscape.org/"&gt;http://inkscape.org/&lt;/a&gt;)&lt;/li&gt; &lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;</description><category>emesene</category><category>exe</category><category>gtk</category><category>installer</category><category>nsis</category><category>portable</category><category>py2exe</category><category>pygtk</category><category>python</category><category>windows</category><guid>http://marianoguerra.org/posts/201010en-how-to-generate-exe-files-and/</guid><pubDate>Sat, 30 Oct 2010 03:19:00 GMT</pubDate></item></channel></rss>