Pyinstaller打包问题

打包过程

  1. 在pip中安装pyinstaller:pip install pyinstaller
  2. 切换到需要打包的目录中,执行pyinstaller -F xxx.py命令,其中xxx.py文件即为需要打包的文件。其他可选的指令:
    • -w 打桌面程序,去掉cmd窗口
    • -i 设置图标,图标后缀为.ico
      如:pyinstaller -F -w -i gen.ico xxx.py
  3. 打包完成以后,打开dist/xxx.exe文件执行即可。

issue

  1. 打包过程中报错:pyinstaller UnicodeDecodeError: 'utf-8' codec can't decode byte 0xce in position 139: invalid continuation byte

    • 打开报错文件的...\site-packages\PyInstaller\compat.py,将 out = out.decode(encoding)改为out = out.decode(encoding, "replace")
  2. 打包过程中会出现:RecursionError: maximum recursion depth exceeded异常,在执行pyinstaller命令后,工作目录下会出现一个与待打包的py文件一样文件名的.spec文件,打卡这个文件,在最开始位置添加如下代码:

    import sys
    sys.setrecursionlimit(1000000)
    

    然后继续执行pyinstaller -F xxx.spec

  3. 打包成功后,运行.exe报错: ModuleNotFoundError: No module named ’numpy.core.__dtype_ctypes’。

    • 打开.spec文件,将'numpy.core._dtype_ctypes'写入到hiddenimports中:
      hiddenimports=['numpy.core._dtype_ctypes']
      
      然后重新执行pyinstaller指令。
  4. pyinstaller可执行文件报错astor,类似

    ......
    File "site-packages/astor/__init__.py",line 24,in <model>
    FileNotFoundError: [Errno 2] no such file or directory:"/temp/_MEI24122/astor/VERSION
    
    • 定位到报错文件的位置,...\site-packages\astor\__init__.py中获取软件版本的三行代码注释掉,这部分代码没有发挥作用。
      ROOT = os.path.dirname(__file__)
      with open(os.path.join(ROOT, 'VERSION')) as version_file:
          __version__ = version_file.read().strip()
      
      然后重新执行pyinstaller指令。

参考

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值