Advertisement
SH1NU11b1

pyinstaller

Jul 29th, 2015
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. #py2exeinstaller
  2.  
  3. PyInstaller can be installed using Pip, the Python package manager.
  4.  
  5. pip install pyinstaller
  6.  
  7. Building the Executable
  8.  
  9. Now, build the executable.
  10.  
  11. pyinstaller.exe --onefile --windowed app.py
  12.  
  13. It’s that easy.
  14.  
  15. If the build was successful, the final executable, app.exe, and any associated files, will be placed in the dist directory, which will be created if it doesn’t exist.
  16.  
  17. Let me briefly describe the options that are being used:
  18.  
  19. --onefile is used to package everything into a single executable. If you do not specify this option, the libraries, etc. will be distributed as separate files alongside the main executable.
  20. --windowed prevents a console window from being displayed when the application is run. If you’re releasing a non-graphical application (i.e. a console application), you do not need to use this option.
  21. app.py the main source file of the application. The basename of this script will be used to name of the executable, however you may specify an alternative executable name using the --name option.
  22.  
  23. See the PyInstaller Manual for more configuration information.
  24.  
  25. You do not need to specify additional modules in the command as they will be automatically pulled via import statements.
  26.  
  27. Note: On my system the final executable is a sizable 8.4 MiB. The executable is relatively large because the Python interpreter, the application code, and all the required libraries are all packaged in (as specified by the --onefile option). Though convenient, there are some implications with this approach which you should be aware of before releasing using this method. See the PyInstaller Manual for more information on bundling.
  28.  
  29. After the build, an app.spec file will be created. This file contains all of the options used to run PyInstaller, and can be fed back into PyInstaller for future builds in place of the command line options, if desired.
  30. Adding an Icon
  31.  
  32. IconEden offers some nice royalty-free icons, so I’ll use one of theirs for this demo. Save an .ico file in the source directory and add the --icon=app.ico option when you run PyInstaller. For example:
  33.  
  34. pyinstaller.exe --onefile --windowed --icon=app.ico app.py
  35.  
  36. This is an example of what an icon looks like when added to the application and viewed through Windows Explorer:
  37.  
  38. Adding Version Information
  39.  
  40. The following file (taken from the PyInstaller test suite) is used by PyInstaller to add version information to the executable. Save this file as version.txt.
  41. version.txt
  42.  
  43. # UTF-8
  44. #
  45. # For more details about fixed file info 'ffi' see:
  46. # http://msdn.microsoft.com/en-us/library/ms646997.aspx
  47. VSVersionInfo(
  48. ffi=FixedFileInfo(
  49. # filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4)
  50. # Set not needed items to zero 0.
  51. filevers=(96, 12, 19, 1),
  52. prodvers=(4, 1, 2, 1),
  53. # Contains a bitmask that specifies the valid bits 'flags'
  54. mask=0x3f,
  55. # Contains a bitmask that specifies the Boolean attributes of the file.
  56. flags=0x0,
  57. # The operating system for which this file was designed.
  58. # 0x4 - NT and there is no need to change it.
  59. OS=0x4,
  60. # The general type of file.
  61. # 0x1 - the file is an application.
  62. fileType=0x1,
  63. # The function of the file.
  64. # 0x0 - the function is not defined for this fileType
  65. subtype=0x0,
  66. # Creation date and time stamp.
  67. date=(0, 0)
  68. ),
  69. kids=[
  70. StringFileInfo(
  71. [
  72. StringTable(
  73. u'040904b0',
  74. [StringStruct(u'CompanyName', u'Fuddy Duddies, Inc. 8 Flossie Dr. Arlington, VA 00001'),
  75. StringStruct(u'ProductName', u'SILLINESS'),
  76. StringStruct(u'ProductVersion', u'2, 0, 3, 0'),
  77. StringStruct(u'InternalName', u'SILLINESS'),
  78. StringStruct(u'OriginalFilename', u'silliness.exe'),
  79. StringStruct(u'FileVersion', u'96, 12, 19, 1'),
  80. StringStruct(u'FileDescription', u'Silly stuff'),
  81. StringStruct(u'LegalCopyright', u'Copyright 2001 Fuddy Duddies, Inc.'),
  82. StringStruct(u'LegalTrademarks', u'SILLINESS is a registered trademark of Fuddy Duddies, Inc.'),])
  83. ]),
  84. VarFileInfo([VarStruct(u'Translation', [1033, 1200])])
  85. ]
  86. )
  87.  
  88. When you have your version.txt file ready, simply add the --version-file=version.txt option to the command line when you run PyInstaller. For example:
  89.  
  90. pyinstaller.exe --onefile --windowed --icon=app.ico --version-file=version.txt app.py
  91.  
  92. Now, the application has an icon and version information.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement