將python源文件打包成exe文件

 

 1 D:\test>pyinstaller -F woqi.py  2 160 INFO: PyInstaller: 3.2.1  3 161 INFO: Python: 2.7.7  4 161 INFO: Platform: Windows-7-6.1.7601-SP1  5 164 INFO: wrote D:\test\woqi.spec  6 174 INFO: UPX is not available.  7 181 INFO: Extending PYTHONPATH with paths  8 ['D:\\test', 'D:\\test']  9 183 INFO: checking Analysis 10 184 INFO: Building Analysis because out00-Analysis.toc is non existent 11 184 INFO: Initializing module dependency graph... 12 188 INFO: Initializing module graph hooks... 13 292 INFO: running Analysis out00-Analysis.toc 14 296 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable 15 required by D:\Python27\python.exe 16 388 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_ 17 1fc8b3b9a1e18e3b_9.0.30729.1_none_3da38fdebd0e6822.manifest 18 391 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_ 19 1fc8b3b9a1e18e3b_9.0.30729.4148_none_acd0e4ffe1daef0a.manifest 20 392 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_ 21 1fc8b3b9a1e18e3b_9.0.30729.4940_none_acd19a1fe1da248a.manifest 22 394 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_ 23 1fc8b3b9a1e18e3b_9.0.30729.7523_none_accf5b75e1dc34f0.manifest 24 480 INFO: Searching for assembly amd64_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.3 25 0729.7523_none ... 26 481 INFO: Found manifest C:\Windows\WinSxS\Manifests\amd64_microsoft.vc90.crt_1f 27 c8b3b9a1e18e3b_9.0.30729.7523_none_08e1eaf5a83f8ea2.manifest 28 483 INFO: Searching for file msvcr90.dll 29 484 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b 30 _9.0.30729.7523_none_08e1eaf5a83f8ea2\msvcr90.dll 31 486 INFO: Searching for file msvcp90.dll 32 486 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b 33 _9.0.30729.7523_none_08e1eaf5a83f8ea2\msvcp90.dll 34 486 INFO: Searching for file msvcm90.dll 35 487 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b 36 _9.0.30729.7523_none_08e1eaf5a83f8ea2\msvcm90.dll 37 575 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_ 38 1fc8b3b9a1e18e3b_9.0.30729.1_none_3da38fdebd0e6822.manifest 39 576 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_ 40 1fc8b3b9a1e18e3b_9.0.30729.4148_none_acd0e4ffe1daef0a.manifest 41 578 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_ 42 1fc8b3b9a1e18e3b_9.0.30729.4940_none_acd19a1fe1da248a.manifest 43 581 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_ 44 1fc8b3b9a1e18e3b_9.0.30729.7523_none_accf5b75e1dc34f0.manifest 45 582 INFO: Adding redirect Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 46 30729, 7523) 47 697 INFO: Caching module hooks... 48 703 INFO: Analyzing D:\test\woqi.py 49 2139 INFO: Processing pre-find module path hook distutils 50 2315 INFO: Loading module hooks... 51 2316 INFO: Loading module hook "hook-distutils.py"... 52 2319 INFO: Loading module hook "hook-encodings.py"... 53 2948 INFO: Looking for ctypes DLLs 54 2950 INFO: Analyzing run-time hooks ... 55 2957 INFO: Looking for dynamic libraries 56 3125 INFO: Looking for eggs 57 3125 INFO: Using Python library C:\Windows\system32\python27.dll 58 3125 INFO: Found binding redirects: 59 [BindingRedirect(name=u'Microsoft.VC90.CRT', language=None, arch=u'amd64', oldVe 60 rsion=(9, 0, 21022, 8), newVersion=(9, 0, 30729, 7523), publicKeyToken=u'1fc8b3b 61 9a1e18e3b')] 62 3134 INFO: Warnings written to D:\test\build\woqi\warnwoqi.txt 63 3177 INFO: checking PYZ 64 3178 INFO: Building PYZ because out00-PYZ.toc is non existent 65 3180 INFO: Building PYZ (ZlibArchive) D:\test\build\woqi\out00-PYZ.pyz 66 3565 INFO: Building PYZ (ZlibArchive) D:\test\build\woqi\out00-PYZ.pyz completed 67 successfully. 68 3611 INFO: checking PKG 69 3611 INFO: Building PKG because out00-PKG.toc is non existent 70 3612 INFO: Building PKG (CArchive) out00-PKG.pkg 71 3647 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 307 72 29, 7523) 73 4856 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully. 74 4865 INFO: Bootloader D:\Python27\lib\site-packages\PyInstaller\bootloader\Windo 75 ws-64bit\run.exe 76 4866 INFO: checking EXE 77 4868 INFO: Building EXE because out00-EXE.toc is non existent 78 4868 INFO: Building EXE from out00-EXE.toc 79 4869 INFO: Appending archive to EXE D:\test\dist\woqi.exe 80 4924 INFO: Building EXE from out00-EXE.toc completed successfully.
View Code

 

1.經過-F 參數對 Python 源文件生成一個獨立的可執行文件,不然是一個帶各類dll和依賴文件的文件夾html

2.在哪一個目錄下打包,這些文件和exe最後就生成在哪裏python

源碼在裏面,在此目錄下運行打包命令,打包後的文件就生成在此目錄git

 

 

 

打包命令-pyinstaller.exegithub

參數:
-F, –onefile 打包成一個exe文件。
-D, –onedir 建立一個目錄,包含exe文件,但會依賴不少文件(默認選項)。
-c, –console, –nowindowed 使用控制檯,無界面(默認)
-w, –windowed, –noconsole 使用窗口,無控制檯ide

通常成功了,會在打包的目錄下生成build和dist文件夾及.spec文件(如:139MailLogin.spec)學習

在cmd窗口,執行打包命令
打包目錄(建議在源代碼所在路徑)>pyinstaller.exe -F 文件路徑(打包目錄和源代碼目錄不一致時,須要用絕對路徑)ui

 

 

3.打包後的.exe可執行程序(只複製.exe文件就能夠,其餘的.spec,dist,bulid文件或目錄均可以刪了)在其餘電腦上運行,不須要該電腦有Python環境spa

4.打包的代碼裏面若是中文沒處理好會致使打包不成功,即便成功運行也會閃退.net

pyinstaller 打包的exe SyntaxError: (unicode error) 'ascii' codec can't decode byte 0xe8 in position 0:  ordinal not in range(128)3d

 

實例:

隨機生成或讓用戶輸入條件生成對應的制卡模擬卡數據和索引文件

源碼:https://github.com/YuanrangChan/woqi-wcpcarddata(打包時注意中文處理)

 

打包命令:

C:\Users\Administrator\Desktop\test>pyinstaller.exe -F C:\Users\Administrator\Desktop\test\RandCarddataIndexWoqi.py

打包後的文件:本身按照上述命令打包便可生成

 

參考:

python學習筆記--將python源文件打包成exe文件 - CSDN博客  https://blog.csdn.net/u010812071/article/details/78507946

Python | 用Pyinstaller打包發佈exe應用_百度經驗  https://jingyan.baidu.com/article/a378c960b47034b3282830bb.html

關於python打包成exe的一點經驗之談 - CSDN博客  https://blog.csdn.net/ztsghjls/article/details/54426169

相關文章
相關標籤/搜索