About fucking pyinstaller reporting UnicodeDecodeError

About fucking pyinstaller reporting UnicodeDecodeError

1. Error message

Traceback (most recent call last):
  File "E:\python_env\env_video_downloader_3_9_2\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "E:\python_env\env_video_downloader_3_9_2\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "E:\python_env\env_video_downloader_3_9_2\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\__main__.py", line 194, in _console_script_run
    run()
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\__main__.py", line 180, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\__main__.py", line 61, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\building\build_main.py", line 971, in main
    build(specfile, distpath, workpath, clean_build)
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\building\build_main.py", line 893, in build
    exec(code, spec_namespace)
  File "E:\Github\video_downloader\launcher.spec", line 7, in <module>
    a = Analysis(
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\building\build_main.py", line 411, in __init__
    self.__postinit__()
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\building\datastruct.py", line 173, in __postinit__
    self.assemble()
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\building\build_main.py", line 574, in assemble
    priority_scripts.append(self.graph.add_script(script))
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\depend\analysis.py", line 269, in add_script
    self._top_script_node = super().add_script(pathname)
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1433, in add_script
    self._process_imports(n)
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2850, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\depend\analysis.py", line 382, in _safe_import_hook
    return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr)
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2301, in _safe_import_hook
    target_modules = self.import_hook(
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1518, in import_hook
    submodule = self._safe_import_module(head, mname, submodule)
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\depend\analysis.py", line 429, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2062, in _safe_import_module
    self._process_imports(n)
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2850, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\depend\analysis.py", line 382, in _safe_import_hook
    return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr)
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2301, in _safe_import_hook
    target_modules = self.import_hook(
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1518, in import_hook
    submodule = self._safe_import_module(head, mname, submodule)
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\depend\analysis.py", line 429, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2062, in _safe_import_module
    self._process_imports(n)
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2850, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\depend\analysis.py", line 382, in _safe_import_hook
    return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr)
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2301, in _safe_import_hook
    target_modules = self.import_hook(
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1518, in import_hook
    submodule = self._safe_import_module(head, mname, submodule)
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\depend\analysis.py", line 429, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2062, in _safe_import_module
    self._process_imports(n)
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2850, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\depend\analysis.py", line 382, in _safe_import_hook
    return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr)
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2301, in _safe_import_hook
    target_modules = self.import_hook(
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1518, in import_hook
    submodule = self._safe_import_module(head, mname, submodule)
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\depend\analysis.py", line 429, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2062, in _safe_import_module
    self._process_imports(n)
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2850, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\depend\analysis.py", line 382, in _safe_import_hook
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\depend\analysis.py", line 429, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2053, in _safe_import_module
    (module, co) = self._load_module(module_name, pathname, loader)
  File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2143, in _load_module
    src = loader.get_source(partname)
  File "<frozen importlib._bootstrap_external>", line 846, in get_source
  File "<frozen importlib._bootstrap_external>", line 628, in decode_source
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 302: invalid continuation byte

2. Resolution process

  At first, I thought it was File "E:\python_env\env_video_downloader_3_9_2\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2143, in _load_module src = loader.get_source(partname) This sentence was wrong , let me check for a long time, the main reason is that the gbk in the lower right corner makes me think that there is a problem with this code.

  But I searched a lot of information on Baidu and Google, and modified it according to their methods, but it still didn't work. Although these materials have no effect, they are still here, in case you who read this article are useful.

  1. PYinstall packaging program encoding error solution 'utf-8' codec can't decode byte 0xce in position 171: invalid continuation b
  2. Encountered ‘utf-8’ codec can’t decode byte 0xd7 in position 2556: invalid continuation byte when python was packaged
  3. "UnicodeDecodeError: 'utf-8' codec can't decode byte 0x93 in position 3965: invalid start byte" when using Pyinstaller
    4.[Solution] Pyinstaller UnicodeDecodeError: 'utf-8' codec can't decode byte
  4. UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdf in position 1313: invalid continuation byte #1775
  5. pyinstaller reports an error when adding icons to -i: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc6 in position 18
  6. "UnicodeDecodeError: 'gbk' codec can't decode byte" appears when pyinstaller is packaged
  7. Pyinstaller packs the Python code into .exe, fills in pit 3: UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xce in position
  8. PYTHON generates EXE,PYINSTALLER code error or flashback, change to CXFREEZE decisively!
  9. Pyinstaller packaging file encoding error Solve the problem of Pyinstaller packaging as executable file encoding error
  10. Xiaobai's question: about pyinstaller packaging executable files
  11. pyinstaller packaging error: RecursionError: maximum recursion depth exceeded
  12. pyinstaller/pyinstaller/wiki/How-to-Report-Bugs
  13. UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte Error when trying to use PyInstaller to amke my code an executable
      After continuous exploration, I found that I was looking for the problem in the wrong direction, because I found that all the codes in the site-package, the lower right corner is gbk, this does not affect its operation, so the problem must appear on my code, and It's not the place in the error message, so I read all my codes and finally found the problem. As shown in the picture below, my file uses gbk encoding, and my other files are utf-8 Encoding, it is because of this that the error is reported.
    When I changed it to utf-8 encoding, I packaged it successfully.

3. Solutions

  If the error message is the same as mine, you might as well check all your codes for gbk encoding. If they are all utf-8 encodings, then look for other solutions. The error point of this packaging error is mainly related to your own code. related.




BTW

Does anyone know what is the cause of this problem? pycharm command line output garbled characters
When I use such a setting, the command line output is normal
But after changing it to utf-8, the command line output is garbled instead. Aren’t the normal encodings all utf-8, and I see that all the information is changed from gbk to utf-8 before it becomes garbled.

Tags: Python pip pyqt programming language

Posted by alex clone on Mon, 23 Jan 2023 14:27:12 +0300