使用pyinstaller生成exe文件

安裝

注:安裝版本是有要求的。

Works out-of-the-box with any Python version 2.7 / 3.4-3.7.

安裝:pip install pyinstaller
pypi地址:https://pypi.org/project/PyInstaller/
官網文檔:https://pyinstaller.readthedocs.io/en/stable/

打包

總共試了兩種方法。都是按照官網操作的。

方式一:
打開cmd窗口,到主文件目錄文件下,運行:
pyinstaller mainscript.py

在腳本同級目錄下會生成了兩個文件夾。
-build
-dist

在dist中有個.exe文件,雙擊就可以執行了。
可以把dist文件夾單獨拿出來,build不知道做什麼用,其中的exe文件與dist中的相同,但是雙擊後會出現閃退。

如果項目下有配置文件需要加載,要把需要的配置文件放入到同exe一級的目錄下。
方式二:
打開cmd窗口,到主文件目錄文件下,運行:
pyinstaller --onefile --windowed myscript.py

還是兩個文件夾。
-build
-dist

dist中只有一個exe文件,但是無法打開。提示:Failed to execute script XXX。

報錯

出錯一:

在安裝pyinstaller模塊包的時候報了一次錯誤。
AttributeError: module 'enum' has no attribute 'IntFlag'

解決:
卸載了enum34模塊
pip uninstall enum34
出錯二:

在堆wxpython程序封裝的時候,出了一次錯誤。
AttributeError: 'str' object has no attribute 'items'

解決:
pip install -U --pre setuptools
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章