pyInstaller打包成exe以及TypeError: an integer is required (got type bytes)解决

  1. pyinstaller安装
pip install pyinstaller
  1. 常用的pyInstaller打包命令参数如下:
  • F:打包 python 程序为单个可执行文件
  • D:打包 python 程序为一个文件夹
  • i: 生成图标,只适用于 windows 平台 (-i 参数后必须接 .ico 结尾的图标文件
  • n: 指定打包后生成文件的名称
  • w:禁止命令行弹出
  1. 打包单个py文件
pyinstaller -F  xxx.py

在这里插入图片描述

  1. 有如图异常,如果有更新异常请更新pip,再安装下方文件
python -m pip install --upgrade pip
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz
  1. 再次运行成功
    在这里插入图片描述
  2. exe文件位置,在所运行的py文件同目录下的dist目录
    在这里插入图片描述
  3. 出现failed to execute script,因为我使用了宋体字体
cur_font = pygame.font.SysFont("宋体", font_size) 

把他换成系统自带的字体就好了

cur_font = pygame.font.SysFont("candara", font_size) 

另一种可能是pygame需要的资源pyinstaller不会给你打包的,需手动加入,即:
最后将pygame需要的资源如图片音乐等文件与exe放在同一目录下,运行exe就不会出错

猜你喜欢

转载自blog.csdn.net/weimeibuqieryu/article/details/103532840