python 打包成exe

第1步:安裝pyinstaller

pip install pyinstaller

第2步:打包exe文件

如果是打包一個py文件,可以使用“pyinstaller -F 待打包文件名”進行打包

pyinstaller main.py

打包完後會在dist目錄下生成一個“待打包文件名”的文件夾,該文件夾下包含“待打包文件.exe”

 

下面是打包我遇到的2個問題

1.RecursionError: maximum recursion depth exceeded 解決方案

  • 執行 pyinstaller,會在當前目錄下生成 filename.spec 文件:
pyinstaller -F filename.py
  • 在 filename.spec 文件頭添加下面語句
import sys
sys.setrecursionlimit(5000)
  • 再次執行 pyinstaller 和 .spec文件
pyinstaller filename.spec

2.Pyinstaller 打包出現 UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xce in position 解決方案

在你打包的命令行中先輸入

chcp 65001 

然後再輸入打包命令:

pyinstaller -F xxx.py
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章