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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章