【Python】pyinstaller模块将py文件打包为windows可执行文件exe
python腳本如果在沒有安裝python的機器上不能運行,所以將腳本打包成exe文件,降低腳本對環境的依賴性,同時運行更加迅速。當然打包的腳本似乎不是在所有的win平臺下都能使用,win7有一部分不能使用,我在win10能夠很好的運行。
準備工作: ?
pyinstaller(http://www.pyinstaller.org/) 首先還是去官網看支持的python版本,不然會很尷尬的
可以直接在python環境使用命令:pip install pyinstaller ? (會自動下載future,pywin32,pyinstaller)
pyinstaller相關參數
如何使用Pyinstaller
1.cmd到python的scripts 找到pyinstaller.exe 本人:D:\zengSoftware\Anaconda\Scripts
2.輸入命令 pyinstaller.exe -F demo.py
比如:pyinstaller.exe -F F:\PythonProject\PythonLession\BaseFunction\translater.py
從cmd最后一行輸出可查找到生成的文件:D:\zengSoftware\Anaconda\Scripts\dist\translater.exe
如果想要對程序設置自定義圖標:pyinstaller -F -i ico_path ?py_path?
首先需要下載一張正常的ico,不能用直接修改后綴的。
下載圖片:https://www.easyicon.net
輸入命令:pyinstaller -F -i F:\PythonProject\PythonLession\BaseFunction\images\net.ico F:\PythonProject\PythonLession\BaseFunction\translater.py
總結
以上是生活随笔為你收集整理的【Python】pyinstaller模块将py文件打包为windows可执行文件exe的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【测试工具】在linux测试环境安装bu
- 下一篇: 【Python】xlwt和xlrd模块写