pyinstaller 打包报错: AttributeError: 'str' object has no attribute 'decode'

说明:

这个错误的原因我也不太清楚,因为我之前打包是没有问题的,这次突然想打包一个文件,然后就报错了,所以,搜索了一番,找到一个大概意思看懂了,但是没有写出解决步骤,所以自己尝试一下,成功解决。所以记录下来,嘻嘻
记录一下高兴的表情

一、问题:

pyinstaller 打包报错:

具体错误代码:

PS D:\zjf_workspace\000、爬虫代码-基础的\scrapy_100_工具\11、视频处理> pyinstaller -F .\cv2视频截帧.py
525 INFO: PyInstaller: 3.5
525 INFO: Python: 3.6.8
527 INFO: Platform: Windows-10-10.0.17134-SP0
530 INFO: wrote D:\zjf_workspace\000、爬虫代码-基础的\scrapy_100_工具\11、视频处理\cv2视频截帧.spec
566 INFO: UPX is not available.
575 INFO: Extending PYTHONPATH with paths
['D:\\zjf_workspace\\000、爬虫代码-基础的\\scrapy_100_工具\\11、视频处理',
 'D:\\zjf_workspace\\000、爬虫代码-基础的\\scrapy_100_工具\\11、视频处理']
576 INFO: checking Analysis
577 INFO: Building Analysis because Analysis-00.toc is non existent
577 INFO: Initializing module dependency graph...
601 INFO: Initializing module graph hooks...
604 INFO: Analyzing base_library.zip ...
Traceback (most recent call last):
  File "d:\tools\python3.6\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "d:\tools\python3.6\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\tools\Python3.6\Scripts\pyinstaller.exe\__main__.py", line 9, in <module>
  File "d:\tools\python3.6\lib\site-packages\PyInstaller\__main__.py", line 111, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "d:\tools\python3.6\lib\site-packages\PyInstaller\__main__.py", line 63, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "d:\tools\python3.6\lib\site-packages\PyInstaller\building\build_main.py", line 844, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "d:\tools\python3.6\lib\site-packages\PyInstaller\building\build_main.py", line 791, in build
    exec(code, spec_namespace)
  File "D:\zjf_workspace\000、爬虫代码-基础的\scrapy_100_工具\11、视频处理\cv2视频截帧.spec", line 17, in <module>
    noarchive=False)
  File "d:\tools\python3.6\lib\site-packages\PyInstaller\building\build_main.py", line 243, in __init__
    self.__postinit__()
  File "d:\tools\python3.6\lib\site-packages\PyInstaller\building\datastruct.py", line 158, in __postinit__
    self.assemble()
  File "d:\tools\python3.6\lib\site-packages\PyInstaller\building\build_main.py", line 349, in assemble
    excludes=self.excludes, user_hook_dirs=self.hookspath)
  File "d:\tools\python3.6\lib\site-packages\PyInstaller\depend\analysis.py", line 608, in initialize_modgraph
    required_mods += collect_submodules(m)
  File "d:\tools\python3.6\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 624, in collect_submodules
    repr(pkg_dir), package))
  File "d:\tools\python3.6\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 83, in exec_statement
    return __exec_python_cmd(cmd)
  File "d:\tools\python3.6\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 72, in __exec_python_cmd
    txt = exec_python(*cmd, env=pp_env)
  File "d:\tools\python3.6\lib\site-packages\PyInstaller\compat.py", line 637, in exec_python
    return exec_command(*cmdargs, **kwargs)
  File "d:\tools\python3.6\lib\site-packages\PyInstaller\compat.py", line 427, in exec_command
    out = out.decode(encoding)
AttributeError: 'str' object has no attribute 'decode'

错误图:
在这里插入图片描述

二、解决步骤:

1、谷歌或者百度搜索:

在这里插入图片描述

上面这俩个我都看了,但是第一个我按他的步骤没有解决问题,博客地址:

https://blog.csdn.net/jylonger/article/details/86537290

第二个:大概意思看懂了,其实错误人家也说出来了,
https://blog.csdn.net/qq_41185868/article/details/82079079

错误提示,意思就是他是字符串类型的,不能再decode,所以,我复制错误的地址,使用pycharm打开,然后复制out = out.decode(encoding)一句,然后搜索进行修改人家的模块(记得先备份一份,防止改错,如果改错还能还原)
在这里插入图片描述

打开之后,下面是我改的方法,很简单,就是在原先的基础上增加个条件,做个判断,如果是字符串类行的,直接跳过,如果是其他的还和之前代码功能一样。

在这里插入图片描述

三、成功运行

再次执行打包命令,成功运行:
高兴在这里插入图片描述
效果图:
在这里插入图片描述

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 撸撸猫 设计师:C马雯娟 返回首页
实付 9.90元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值