一、使用pyinstaller 完成对python程序到可执行文件转换.

官网: http://www.pyinstaller.org/ 下载与操作系统相匹配的版本. 目前pyinstaller 只支持2.3 - 2.7。 不支持python.3

二、将下载的pyinstaller-2.0.zip文件解压,解压后可直接使用。

    pyinstaller不依赖python,因此不需要放入到 site-packages此目录.

三、pyinstaller 使用及参数

 
  
  1. C:\pyinstaller-2.0>python pyinstaller.py -F -w --icon=E:\p_w_picpaths\96.ico MonitorWin32Process.py 
  2. 38 INFO: wrote C:\pyinstaller-2.0\MonitorWin32Process\MonitorWin32Process.spec 
  3. 60 INFO: Testing for ability to set icons, version resources... 
  4. 75 INFO: ... resource update available 
  5. 78 INFO: UPX is not available. 
  6. 1154 INFO: checking Analysis 
  7. 1156 INFO: building Analysis because out00-Analysis.toc non existent 
  8. 1157 INFO: running Analysis out00-Analysis.toc 
  9. 1159 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable 
  10.  
  11. 1253 INFO: Searching for assembly x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21 
  12. 022.8_none ... 
  13. 1255 INFO: Found manifest C:\Windows\WinSxS\Manifests\x86_microsoft.vc90.crt_1fc 
  14. 8b3b9a1e18e3b_9.0.21022.8_none_bcb86ed6ac711f91.manifest 
  15. 1258 INFO: Searching for file msvcr90.dll 
  16. 1259 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_ 
  17. 9.0.21022.8_none_bcb86ed6ac711f91\msvcr90.dll 
  18. 1259 INFO: Searching for file msvcp90.dll 
  19. 1261 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_ 
  20. 9.0.21022.8_none_bcb86ed6ac711f91\msvcp90.dll 
  21. 1262 INFO: Searching for file msvcm90.dll 
  22. 1264 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_ 
  23. 9.0.21022.8_none_bcb86ed6ac711f91\msvcm90.dll 
  24. 1365 INFO: Analyzing C:\pyinstaller-2.0\support\_pyi_bootstrap.py 
  25. 2440 INFO: Analyzing C:\pyinstaller-2.0\PyInstaller\loader\archive.py 
  26. 2552 INFO: Analyzing C:\pyinstaller-2.0\PyInstaller\loader\carchive.py 
  27. 2674 INFO: Analyzing C:\pyinstaller-2.0\PyInstaller\loader\iu.py 
  28. 2705 INFO: Analyzing MonitorWin32Process.py 
  29. 2779 WARNING: pywintypes is changing its name to pywintypes27 
  30. 2871 WARNING: pythoncom is changing its name to pythoncom27 
  31. 3535 INFO: Hidden import 'encodings' has been found otherwise 
  32. 3536 INFO: Looking for run-time hooks 
  33. 3537 INFO: Analyzing rthook C:\pyinstaller-2.0\support/rthooks/pyi_rth_encodings 
  34. .py 
  35. 3621 INFO: Analyzing rthook C:\pyinstaller-2.0\support/rthooks/pyi_rth_versioned 
  36. dll.py 
  37. 3723 INFO: Analyzing rthook C:\pyinstaller-2.0\support/rthooks/pyi_rth_win32comg 
  38. enpy.py 
  39. 3833 INFO: Analyzing rthook C:\pyinstaller-2.0\support/rthooks/pyi_rth_versioned 
  40. dll.py 
  41. 4118 INFO: Adding Microsoft.VC90.MFC to dependent assemblies of final executable 
  42.  
  43. 4192 INFO: Searching for assembly x86_Microsoft.VC90.MFC_1fc8b3b9a1e18e3b_9.0.21 
  44. 022.8_none ... 
  45. 4193 INFO: Found manifest C:\Python27\lib\site-packages\Pythonwin\Microsoft.VC90 
  46. .MFC.manifest 
  47. 4195 INFO: Searching for file mfc90.dll 
  48. 4196 INFO: Found file C:\Python27\lib\site-packages\Pythonwin\mfc90.dll 
  49. 4197 INFO: Searching for file mfc90u.dll 
  50. 4197 INFO: Found file C:\Python27\lib\site-packages\Pythonwin\mfc90u.dll 
  51. 4199 INFO: Searching for file mfcm90.dll 
  52. 4200 INFO: Found file C:\Python27\lib\site-packages\Pythonwin\mfcm90.dll 
  53. 4200 INFO: Searching for file mfcm90u.dll 
  54. 4202 INFO: Found file C:\Python27\lib\site-packages\Pythonwin\mfcm90u.dll 
  55. 4856 INFO: Warnings written to C:\pyinstaller-2.0\MonitorWin32Process\build\pyi. 
  56. win32\MonitorWin32Process\warnMonitorWin32Process.txt 
  57. 4866 INFO: checking PYZ 
  58. 4867 INFO: rebuilding out00-PYZ.toc because out00-PYZ.pyz is missing 
  59. 4868 INFO: building PYZ out00-PYZ.toc 
  60. 6252 INFO: checking PKG 
  61. 6253 INFO: rebuilding out00-PKG.toc because out00-PKG.pkg is missing 
  62. 6253 INFO: building PKG out00-PKG.pkg 
  63. 8202 INFO: checking EXE 
  64. 8203 INFO: rebuilding out00-EXE.toc because MonitorWin32Process.exe missing 
  65. 8205 INFO: building EXE from out00-EXE.toc 
  66. 8212 INFO: SRCPATH [('E:\\p_w_picpaths\\96.ico', None)] 
  67. 8231 INFO: Updating icons from ['E:\\p_w_picpaths\\96.ico'] to c:\users\bo\appdata\loc 
  68. al\temp\tmp827iux 
  69. 8232 INFO: Writing RT_GROUP_ICON 0 resource with 76 bytes 
  70. 8233 INFO: Writing RT_ICON 1 resource with 872 bytes 
  71. 8233 INFO: Writing RT_ICON 2 resource with 3240 bytes 
  72. 8235 INFO: Writing RT_ICON 3 resource with 7336 bytes 
  73. 8236 INFO: Writing RT_ICON 4 resource with 12840 bytes 
  74. 8236 INFO: Writing RT_ICON 5 resource with 28840 bytes 
  75. 8266 INFO: Appending archive to EXE C:\pyinstaller-2.0\MonitorWin32Process\dist\ 
  76. MonitorWin32Process.exe 
  77.  
  78. C:\pyinstaller-2.0> 

 正常情况下会在当前目录下,生成与python文件名相同的目录,可执行程序在dist 目录下.

 

 
  
  1. -F 生成一个文件及生成一个exe文件 
  2. -W --windowed, --noconsole 使用一个子系统,不使用console及没有那个黑框 
  3. --icon 可自定义图标