当我用pyinstaller编译Python代码时,我遇到了一个问题。
python代码使用os、datetime、python-pptx和tqdm包。
当我使用下面的这一行编译:
C:\test>pyinstaller -F Final_ver.py
我在下面看到这个错误消息:(抱歉留言太长)
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
我尝试了下面提到的解决方案,但它没有工作。
https://stackoverflow.com/a/47709800/18876363
更改Python\Lib\site-packages\Pyinstaller\compat.py
中的行out = out.decode(encoding)
到out = out.decode(encoding, errors='ignore')
也尝试了out = out.decode(encoding, "replace")
只是想知道是否有其他方法来解决这个问题?
1条答案
按热度按时间s3fp2yjn1#
我发现我的源代码是用ASCII编码的;因为我使用visual studio,发现常见的编码是ascii。只是通过编码的'保存为'来解决。下面的链接是我在microscoft上读到的。!
Link