用pyinstaller打包python代碼
1. pyinstaller的作用
開發完python代碼後,如果直接把源碼給用戶,用戶還需要自己去安裝python和相關的庫文件,這明顯太不人性化了。此時,就需要pyinstaller登場了。用pyinstaller可以將python代碼打包成一個exe文件,客戶直接可以拿來運行就可以了。
2. pyinstaller安裝
pip install pyinstaller
3. pyinstaller使用
使用環境:
- win10 64bit系統
- python 3.7.5
- pyinstaller安裝位置:
C:\Users\wbin\AppData\Local\Programs\Python\Python37\Scripts\pyinstaller
- python代碼文件名稱:hello.py
- exe圖標文件名稱:title.icon
C:\Users\wbin\AppData\Local\Programs\Python\Python37\Scripts\pyinstaller -F -i title.icon -w hello.py
參數簡介:
- -F:將python代碼、庫文件打包成單個的exe文件。
- -i:指定exe文件的圖標。
- -w:程序運行時不顯示命令行窗口(僅對Windows有效)