Tag Archives: Pyinstaller Package Error

[Solved] Pyinstaller package Error: AttributeError: ‘str’ object has no attribute ‘decode’

(Ven) F:\project\Python\Freightsmart>pyinstaller -D sutep.py
83 INFO: PyInstaller: 4.7
83 INFO: Python: 3.7.4
83 INFO: Platform: Windows-10-10.0.19041-SP0
84 INFO: wrote F:\project\Python\Freightsmart\sutep.spec
90 INFO: UPX is not available.
114 INFO: Extending PYTHONPATH with paths
['F:\\project\\Python\\Freightsmart']
Traceback (most recent call last):
  File "E:\Python\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "E:\Python\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "F:\project\Python\Ven\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
  File "f:\project\python\ven\lib\site-packages\PyInstaller\__main__.py", line 124, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "f:\project\python\ven\lib\site-packages\PyInstaller\__main__.py", line 58, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "f:\project\python\ven\lib\site-packages\PyInstaller\building\build_main.py", line 782, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "f:\project\python\ven\lib\site-packages\PyInstaller\building\build_main.py", line 714, in build
    exec(code, spec_namespace)
  File "F:\project\Python\Freightsmart\sutep.spec", line 19, in <module>
    noarchive=False)
  File "f:\project\python\ven\lib\site-packages\PyInstaller\building\build_main.py", line 245, in __init__
    self.hookspath += discover_hook_directories()
  File "f:\project\python\ven\lib\site-packages\PyInstaller\building\build_main.py", line 116, in discover_hook_directories
    """
  File "f:\project\python\ven\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 91, in exec_statement
    return __exec_statement(statement, capture_stdout=True)
  File "f:\project\python\ven\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 75, in __exec_statement
    return __exec_python_cmd(cmd, capture_stdout=capture_stdout)
  File "f:\project\python\ven\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 66, in __exec_python_cmd
    txt = compat.exec_python(*cmd, env=pp_env)
  File "f:\project\python\ven\lib\site-packages\PyInstaller\compat.py", line 546, in exec_python
    return exec_command(*cmdargs, **kwargs)
  File "f:\project\python\ven\lib\site-packages\PyInstaller\compat.py", line 348, in exec_command
    out = out.decode(encoding)
AttributeError: 'str' object has no attribute 'decode'

 File "f:\project\python\ven\lib\site-packages\PyInstaller\compat.py", line 348, in exec_command

Commont out
        # if encoding:
        #     out = out.decode(encoding)
        # else:

Pyinstaller Package Error: failed to execute script main [How to Solve]

When packaging, replace the code with: pyinstaller --hidden-import=pkg_resources -F main.py Can succeed.

It was originally designed to hide the code window during packaging. The absolute path was used. This problem was solved after changing to the above code.

Usage: pyinstaller38 --hidden-import=pkg_resources -F -w -i m4.ico main.py