標籤:.exe build pac form michael 詳細資料 text appdata cin
我們知道,Python很優雅,很值得學習。但是Python是解釋性語言,代碼需要有Python解譯器才能執行,相比較我們平時直接運行exe等可執行檔多了一步的麻煩。
於是,希望能將Python程式打包成exe,使用起來多方便。
PyInstaller可以將Python程式打包成Windows(當然也包括Linux, Mac OS X, Solaris and AIX)下可執行檔EXE檔案,目前支援python 2.7 and 3.3—3.6版本。
官網:http://www.pyinstaller.org/
使用pip命令安裝:pip install PyInstaller(會將依賴Pywin32也安裝,方便)
安裝後看下pyinstaller的版本: pyinstaller --version
下面開始使用pyinstaller打包程式:python2.7+pyinstaller3.3
1、建立py檔案: pyInstaller.py
pyInstaller.py
1 2 3 45 |
|
# pyinstaller # pip install pyinstaller
print "Hello Python!"msg = input() |
2、執行打包:pyinstaller pyInstaller.py
常用選項參數:pyinstaller -h 擷取詳細資料
-F 表示產生單個可執行檔
-w 表示去掉控制台視窗,這在GUI介面時非常有用。不過如果是命令列程式的話那就把這個選項刪除吧!
-p 表示你自己自訂需要載入的類路徑,一般情況下用不到
-i 表示可執行檔的表徵圖
pyinstaller pyInstaller.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
C:\Python27\src>pyinstaller pyInstaller.py 60 INFO: PyInstaller: 3.3.1 60 INFO: Python: 2.7.15 60 INFO: Platform: Windows-7-6.1.7601-SP1 61 INFO: wrote C:\Python27\src\pyInstaller.spec 62 INFO: UPX is not available. 65 INFO: Extending PYTHONPATH with paths [‘C:\\Python27\\src‘, ‘C:\\Python27\\src‘] 68 INFO: checking Analysis 68 INFO: Building Analysis because out00-Analysis.toc is non existent 69 INFO: Initializing module dependency graph... 71 INFO: Initializing module graph hooks... 156 INFO: running Analysis out00-Analysis.toc 189 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable required by c:\python27\python.exe 1780 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1 fc8b3b9a1e18e3b_9.0.30729.1_none_8550c6b5d18a9128.manifest 1782 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1 fc8b3b9a1e18e3b_9.0.30729.4940_none_f47ed0f6f6564d90.manifest 1791 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1 fc8b3b9a1e18e3b_9.0.30729.6161_none_f480bfaef65491a5.manifest 1823 INFO: Searching for assembly x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30 729.6161_none ... 1824 INFO: Found manifest C:\Windows\WinSxS\Manifests\x86_microsoft.vc90.crt_1fc 8b3b9a1e18e3b_9.0.30729.6161_none_50934f2ebcb7eb57.manifest 1825 INFO: Searching for file msvcr90.dll 1825 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_ 9.0.30729.6161_none_50934f2ebcb7eb57\msvcr90.dll 1825 INFO: Searching for file msvcp90.dll 1825 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_ 9.0.30729.6161_none_50934f2ebcb7eb57\msvcp90.dll 1825 INFO: Searching for file msvcm90.dll 1827 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_ 9.0.30729.6161_none_50934f2ebcb7eb57\msvcm90.dll 1856 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1 fc8b3b9a1e18e3b_9.0.30729.1_none_8550c6b5d18a9128.manifest 1857 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1 fc8b3b9a1e18e3b_9.0.30729.4940_none_f47ed0f6f6564d90.manifest 1858 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1 fc8b3b9a1e18e3b_9.0.30729.6161_none_f480bfaef65491a5.manifest 1859 INFO: Adding redirect Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 6161) 2138 INFO: Caching module hooks... 2144 INFO: Analyzing C:\Python27\src\pyInstaller.py 2144 INFO: Loading module hooks... 2146 INFO: Loading module hook "hook-encodings.py"... 5555 INFO: Looking for ctypes DLLs 5555 INFO: Analyzing run-time hooks ... 5561 INFO: Looking for dynamic libraries 5680 INFO: Looking for eggs 5682 INFO: Using Python library C:\Windows\system32\python27.dll 5682 INFO: Found binding redirects: [BindingRedirect(name=u‘Microsoft.VC90.CRT‘, language=None, arch=u‘x86‘, oldVers ion=(9, 0, 21022, 8), newVersion=(9, 0, 30729, 6161), publicKeyToken=u‘1fc8b3b9a 1e18e3b‘)] 5685 INFO: Warnings written to C:\Python27\src\build\pyInstaller\warnpyInstaller .txt 5711 INFO: Graph cross-reference written to C:\Python27\src\build\pyInstaller\xr ef-pyInstaller.html 5748 INFO: checking PYZ 5748 INFO: Building PYZ because out00-PYZ.toc is non existent 5749 INFO: Building PYZ (ZlibArchive) C:\Python27\src\build\pyInstaller\out00-PY Z.pyz 5993 INFO: Building PYZ (ZlibArchive) C:\Python27\src\build\pyInstaller\out00-PY Z.pyz completed successfully. 6028 INFO: checking PKG 6029 INFO: Building PKG because out00-PKG.toc is non existent 6029 INFO: Building PKG (CArchive) out00-PKG.pkg 6048 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully. 6051 INFO: Bootloader c:\python27\lib\site-packages\PyInstaller\bootloader\Windo ws-32bit\run.exe 6051 INFO: checking EXE 6051 INFO: Building EXE because out00-EXE.toc is non existent 6052 INFO: Building EXE from out00-EXE.toc 6052 INFO: Appending archive to EXE C:\Python27\src\build\pyInstaller\pyInstalle r.exe 6054 INFO: Building EXE from out00-EXE.toc completed successfully. 6060 INFO: checking COLLECT 6061 INFO: Building COLLECT because out00-COLLECT.toc is non existent 6063 INFO: Building COLLECT out00-COLLECT.toc 6073 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 307 29, 6161) 6291 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 307 29, 6161) 6297 INFO: Updating manifest in C:\Users\Michael\AppData\Roaming\pyinstaller\bin cache00_py27_32bit\python27.dll 6382 INFO: Updating resource type 24 name 2 language 1033 6572 INFO: Building COLLECT out00-COLLECT.toc completed successfully. |
執行完畢後,會在目前的目錄的dist 中產生pyInstaller.exe
Python打包-Pyinstaller