PyInstaller打包python程序

文章介绍了使用PyInstaller打包Python程序时遇到的四个问题及解决方案。问题包括:pip版本过高导致模块找不到、运行时缺少dll文件、在不同环境下打包失败以及Gooey库的编码问题。提供的解决方案包括降低pip版本、指定dll路径、修改Gooey源代码以处理编码错误。
摘要由CSDN通过智能技术生成

PyInstaller打包python程序


PyInstaller打包python程序:例:打包外参变换修正


问题1

打包时报错

from PyInstaller.__main__ import run
ModuleNotFoundError: No module named 'PyInstaller'

原因分析:

github isuss 上说pip的高版本导致的,成功的案例pip==19.0.3


解决方案:

降pip版本为19.0.3


问题2

打包后运行缺少dll


原因分析:

找不到dll


解决方案:

打包时加入dll路径
pyinstaller -D -p .\DLLs xxx\fine_tuning_extrinsic.py


问题3

无法使用不同环境中的pyinstaller 进行打包,即使加入了dll路径


问题4

Exception in thread Thread-1:
Traceback (most recent call last):
File "threading.py", line 932, in _bootstrap_inner
File "threading.py", line 870, in run
File "gooey\gui\processor.py", line 70, in _forward_stdout
File "gooey\gui\processor.py", line 84, in _extract_progress
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc4 in position 0: invalid continuation byte

原因分析:

gooey编码问题


解决方案:

参考:https://cloud.tencent.com/developer/article/1981252
修改:
D:\xxx\Lib\site-packages\gooey\gui\processor.py

   pub.send_message(events.PROGRESS_UPDATE, progress=_progress)
        if _progress is None or self.hide_progress_msg is False:
            try:
                pub.send_message(events.CONSOLE_UPDATE,
                                 msg=line.decode(self.encoding))
            except UnicodeDecodeError :
                pub.send_message(events.CONSOLE_UPDATE,
                                 msg=line.decode("gbk"))
    pub.send_message(events.EXECUTION_COMPLETE)
 
def _extract_progress(self, text):
    '''
    Finds progress information in the text using the
    user-supplied regex and calculation instructions
    '''
    # monad-ish dispatch to avoid the if/else soup
    try:
        find = partial(re.search, string=text.strip().decode(self.encoding))
    except UnicodeDecodeError :
        find = partial(re.search, string=text.strip().decode("gbk"))

pyinstaller -D -p .\DLLs xxx\fine_tuning_extrinsic.py
bingo!


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值