Configure py2exe for your project
1) Build a setup.py file.
I’m using this on my project – the pytodolist
[python]
# setup.py
from distutils.core import setup
import py2exe
import glob
opts = {
“py2exe”: {
“excludes”: “pango,atk,gobject”,
“dll_excludes”: [
"iconv.dll","intl.dll","libatk-1.0-0.dll",
"libgdk_pixbuf-2.0-0.dll","libgdk-win32-2.0-0.dll",
"libglib-2.0-0.dll","libgmodule-2.0-0.dll",
"libgobject-2.0-0.dll","libgthread-2.0-0.dll",
"libgtk-win32-2.0-0.dll","libpango-1.0-0.dll",
"libpangowin32-1.0-0.dll"],
}
}
setup(
name = “PyToDoList”,
description = “A simple ToDoList Program”,
version = “0.61″,
windows = [
{"script": "todo.py",
"icon_resources": [(1, "checker1.ico")]
}
],
options=opts,
data_files=[("todo.db"),("jojopix.png"),("checker1.ico")],
)
[/python]
Compiling the Installer using NSIS.
Usually the file extension of the NSI script is .nsi. For more information on NSIS scripting, there’s a tutorial available at sourceforge site. Below is my sample NSIS script:
[actionscript]
;——————————–
;Include Modern UI
!include “MUI.nsh”
;——————————–
;General
;Name and file
Name “PyToDoList”
OutFile “PyToDoList.exe”
;Default installation folder
InstallDir “$PROGRAMFILES\PyToDoList”
;Get installation folder from registry if available
InstallDirRegKey HKCU “Software\PyToDoList” “”
;——————————–
;Interface Settings
!define MUI_ABORTWARNING
;——————————–
;Pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE “..\License.txt”
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
;——————————–
;Languages
!insertmacro MUI_LANGUAGE “English”
;——————————–
;Installer Sections
Section “Package” SecDummy
SetOutPath “$INSTDIR”
File “..\dist\*.*”
;Store installation folder
WriteRegStr HKCU “Software\PyToDoList” “” $INSTDIR
;Create uninstaller
WriteUninstaller “$INSTDIR\Uninstall.exe”
CreateShortCut “$INSTDIR\PyToDoList.lnk” “$INSTDIR\todo.exe”
SetOutPath “$SMPROGRAMS\MegSoft Solutions\”
CopyFiles “$INSTDIR\PyToDoList.lnk” “$SMPROGRAMS\MegSoft Solutions\”
CopyFiles “$INSTDIR\PyToDoList.lnk” “$DESKTOP\”
Delete “$INSTDIR\PyToDoList.lnk”
CreateShortCut “$SMPROGRAMS\GemSoft Solutions\Uninstall.lnk” “$INSTDIR\Uninstall.exe”
SectionEnd
Section “GTK+” SecDummy2
SetOutPath “$INSTDIR\”
File “..\..\gtklib\*.dll”
SetOutPath “$INSTDIR\etc\fonts\”
File “..\..\gtklib\etc\fonts\*.*”
SetOutPath “$INSTDIR\etc\gtk-2.0\”
File “..\..\gtklib\etc\gtk-2.0\*.*”
SetOutPath “$INSTDIR\etc\pango\”
File “..\..\gtklib\etc\pango\*.*”
SetOutPath “$INSTDIR\lib\gtk-2.0\2.4.0\loaders\”
File “..\..\gtklib\lib\gtk-2.0\2.4.0\loaders\*.*”
SetOutPath “$INSTDIR\lib\gtk-2.0\2.4.0\engines\”
File “..\..\gtklib\lib\gtk-2.0\2.4.0\engines\*.*”
SetOutPath “$INSTDIR\lib\gtk-2.0\2.4.0\immodules\”
File “..\..\gtklib\lib\gtk-2.0\2.4.0\immodules\*.*”
SetOutPath “$INSTDIR\lib\pango\1.4.0\modules\”
File “..\..\gtklib\lib\pango\1.4.0\modules\*.*”
SetOutPath “$INSTDIR\share\themes\Default\gtk-2.0\”
File “..\..\gtklib\share\themes\Default\gtk-2.0\*.*”
SetOutPath “$INSTDIR\share\themes\MS-Windows\gtk-2.0\”
File “..\..\gtklib\share\themes\MS-Windows\gtk-2.0\*.*”
SectionEnd
;——————————–
;Descriptions
;Language strings
LangString DESC_SecDummy ${LANG_ENGLISH} “Main Package”
LangString DESC_SecDummy2 ${LANG_ENGLISH} “GTK+ Package. To be installed if you dont have pre installed GTK+”
;Assign language strings to sections
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SecDummy} $(DESC_SecDummy)
!insertmacro MUI_DESCRIPTION_TEXT ${SecDummy2} $(DESC_SecDummy2)
!insertmacro MUI_FUNCTION_DESCRIPTION_END
;——————————–
;Uninstaller Section
Section “Uninstall”
Delete “$INSTDIR\*.*”
Delete “$DESKTOP\PyToDoList.lnk”
Delete “$SMPROGRAMS\GemSoft Solutions\PyToDoList.lnk”
Delete “$SMPROGRAMS\GemSoft Solutions\Uninstall.lnk”
RMDir “$SMPROGRAMS\GemSoft Solutions\”
RMDir /r “$INSTDIR\etc\”
RMDir /r “$INSTDIR\lib\”
RMDir /r “$INSTDIR\share\”
RMDir “$INSTDIR”
DeleteRegKey /ifempty HKCU “Software\PyToDoList”
SectionEnd
[/actionscript]
There are two options for compiling .nsi file.
- Compile the .nsi file by right clicking it and select the Compile NSIS. The
output exe is the installer of the file.
- Issue the command makensis . This will then generate the output exe file.