I have an issue when i compile a python code with pyinstaller.
The python code is using os, datetime, python-pptx, and tqdm packages.
When i use this line below for compile:
C:\test>pyinstaller -F Final_ver.py
I get this error message below: (Sorry for Long message)
301 INFO: PyInstaller: 5.11.0
301 INFO: Python: 3.11.3
322 INFO: Platform: Windows-10-10.0.19045-SP0
335 INFO: wrote C:\test\Final_ver.spec
338 INFO: UPX is not available.
340 INFO: Extending PYTHONPATH with paths
['C:\\test']
722 INFO: checking Analysis
722 INFO: Building Analysis because Analysis-00.toc is non existent
723 INFO: Initializing module dependency graph...
725 INFO: Caching module graph hooks...
739 INFO: Analyzing base_library.zip ...
2575 INFO: Loading module hook 'hook-heapq.py' from 'C:\\Users\\Jess\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\PyInstaller\\hooks'...
2849 INFO: Loading module hook 'hook-encodings.py' from 'C:\\Users\\Jess\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\PyInstaller\\hooks'...
4226 INFO: Loading module hook 'hook-pickle.py' from 'C:\\Users\\Jess\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\PyInstaller\\hooks'...
5516 INFO: Caching module dependency graph...
5612 INFO: running Analysis Analysis-00.toc
5615 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by C:\Users\Jess\AppData\Local\Programs\Python\Python311\python.exe
5773 INFO: Analyzing C:\test\Final_ver.py
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\Users\Jess\AppData\Local\Programs\Python\Python311\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
File "C:\Users\Jess\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\__main__.py", line 194, in _console_script_run
run()
File "C:\Users\Jess\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\__main__.py", line 180, in run
run_build(pyi_config, spec_file, **vars(args))
File "C:\Users\Jess\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\__main__.py", line 61, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "C:\Users\Jess\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\building\build_main.py", line 1006, in main
build(specfile, distpath, workpath, clean_build)
File "C:\Users\Jess\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\building\build_main.py", line 928, in build
exec(code, spec_namespace)
File "C:\test\Final_ver.spec", line 7, in <module>
a = Analysis(
^^^^^^^^^
File "C:\Users\Jess\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\building\build_main.py", line 428, in __init__
self.__postinit__()
File "C:\Users\Jess\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\building\datastruct.py", line 184, in __postinit__
self.assemble()
File "C:\Users\Jess\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\building\build_main.py", line 581, in assemble
priority_scripts.append(self.graph.add_script(script))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Jess\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\depend\analysis.py", line 268, in add_script
self._top_script_node = super().add_script(pathname)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Jess\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1419, in add_script
contents = fp.read() + '\n'
^^^^^^^^^
File "<frozen codecs>", line 322, in decode
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb3 in position 4055: invalid start byte
I tried the solution mention in below but It's not worked.
https://stackoverflow.com/a/47709800/18876363
change the line in the Python\Lib\site-packages\Pyinstaller\compat.py
out = out.decode(encoding)
to
out = out.decode(encoding, errors='ignore')
and also tried with
out = out.decode(encoding, "replace")
Just wonder Is there any other approaches for solving this issue?
I found out my source code was encoded by ascii; as i using visual studio and found out common encoding was ascii. just solved by 'save as' with encoding. A link below is what i read on microscoft..!