https://taste.tuxfamily.org/wiki/index.php?title=Create_an_.exe_file_from_a_python_script&feed=atom&action=historyCreate an .exe file from a python script - Revision history2024-03-29T05:45:06ZRevision history for this page on the wikiMediaWiki 1.29.0https://taste.tuxfamily.org/wiki/index.php?title=Create_an_.exe_file_from_a_python_script&diff=33&oldid=prevTtsiodras: 1 revision imported2017-08-04T21:01:51Z<p>1 revision imported</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<tr style='vertical-align: top;' lang='en'>
<td colspan='1' style="background-color: white; color:black; text-align: center;">← Older revision</td>
<td colspan='1' style="background-color: white; color:black; text-align: center;">Revision as of 21:01, 4 August 2017</td>
</tr><tr><td colspan='2' style='text-align: center;' lang='en'><div class="mw-diff-empty">(No difference)</div>
</td></tr></table>Ttsiodrashttps://taste.tuxfamily.org/wiki/index.php?title=Create_an_.exe_file_from_a_python_script&diff=32&oldid=prevPbradley at 08:27, 29 May 20122012-05-29T08:27:32Z<p></p>
<p><b>New page</b></p><div>There are lots of alternatives to package a python script to a stand-alone executable. For example: [http://www.pyinstaller.org/ PyInstaller], [http://sourceforge.net/projects/py2exe py2exe], [http://cx-freeze.sourceforge.net/ cx_Freeze] all offer cross-platform solutions.<br />
<br />
To package the Windows TASTE GUI, which uses [http://www.pyside.org/ PySide] bindings for [http://qt.nokia.com/ Qt] to a stand-alone .exe file [http://www.pyinstaller.org/ PyInstaller] is used.<br />
<br />
The following packages are needed:<br />
<br />
* The Qt Software Development Kit, Qt SDK. Available from http://qt.nokia.com/downloads. When installing, select the custom installation and make sure you install the Desktop library version that matches with the Pyside bindings you use. Also, the [http://www.mingw.org/ MinGW environment] should be installed.<br />
* Python interpreter for Windows, Python 2.7.3 Windows Installer. Available from http://www.python.org/download.<br />
* Pyside Binaries for Windows. Available from http://qt-project.org/wiki/PySide_Binaries_Windows. Make sure you download and install the version that matches your QT library version and your Python interpreter version.<br />
* setuptools. Available from http://pypi.python.org/pypi/setuptools.<br />
* Python for Windows extensions (PyWin32) only if you are using python 2.6 or above. Available from: http://sourceforge.net/projects/pywin32.<br />
All five tools should be installed following the order in which the are presented. These tools can be easily installed as they are bundled as executables.<br />
<br />
Finally, you will also need the TASTE GUI python sources to build the executable.<br />
<br />
Then,download the [http://www.pyinstaller.org/ PyInstaller] zip file from http://www.pyinstaller.org/.<br />
<br />
Next, extract the content of the zip file and open a command window in that directory.<br />
<br />
Type the following to configure the PyInstaller setup:<br />
<syntaxhighlight lang="dos"><br />
C:\PyInstaller> python Configure.py</syntaxhighlight> <br />
<br />
This will only have to be run once unless you change your python version.<br />
<br />
Next, create a spec file for the project:<br />
<syntaxhighlight lang="dos"><br />
C:\PyInstaller> python Makespec.py -w --icon=<iconfile.ico> tasteGUI.py</syntaxhighlight> <br />
<br />
This command will create a spec file ''.\tasteGUI\tasteGUI.spec'' that will produce a single directory deployment (use the ''-F'' to deploy a single file) that uses the Windows subsystem executable (''-w'') and adds the ''iconfile.ico'' icon.<br />
<br />
Finally, build the project to a stand-alone executable:<br />
<syntaxhighlight lang="dos"><br />
C:\PyInstaller> python Build.py .\tasteGUI\tasteGUI.spec</syntaxhighlight><br />
<br />
The final generated file will be place in the ''dist'' directory under ''.\tasteGUI''.<br />
<br />
Note: If you want to generate the executable and its associated *.dlls with the minimum size download UPX from http://upx.sourceforge.net/, install it and make sure you add it to your path before you run configure the PyInstaller setup. Then, add the ''-X'' option when generating the spec file:<br />
<syntaxhighlight lang="dos"><br />
C:\PyInstaller> python Makespec.py -X -w --icon=<iconfile.ico> tasteGUI.py</syntaxhighlight></div>Pbradley