为什么python使用Pyinstaller打包成exe,只有spec文件?

为什么python使用Pyinstaller打包成exe,只有spec文件?

问题描述

使用Pyinstaller将python脚本文件打包成exe,但是生成的文件夹里没有exe文件
打包使用的命令是
pyinstaller -F -w test.py

报错信息

Traceback (most recent call last):

File "D:\Anaconda3\envs\guanji\lib\runpy.py", line 193, in _run_module_as_main "__main__", mod_spec)

File "D:\Anaconda3\envs\guanji\lib\runpy.py", line 85, in _run_code

exec(code, run_globals)

File "D:\Anaconda3\envs\guanji\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>

File "D:\Anaconda3\envs\guanji\lib\site-packages\PyInstaller\__main__.py", line 194, in _console_script_run run()

File "D:\Anaconda3\envs\guanji\lib\site-packages\PyInstaller\__main__.py", line 180, in run run_build(pyi_config, spec_file, **vars(args))

File "D:\Anaconda3\envs\guanji\lib\site-packages\PyInstaller\__main__.py", line 61, in run_build

PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)

File "D:\Anaconda3\envs\guanji\lib\site-packages\PyInstaller\building\build_main.py", line 1019, in main

build(specfile, distpath, workpath, clean_build)

File "D:\Anaconda3\envs\guanji\lib\site-packages\PyInstaller\building\build_main.py", line 944, in build

exec(code, spec_namespace)

File "D:\programing\python\guanji.spec", line 20, in <module>

noarchive=False,

File "D:\Anaconda3\envs\guanji\lib\site-packages\PyInstaller\building\build_main.py", line 429, in __init__

self.__postinit__()

File "D:\Anaconda3\envs\guanji\lib\site-packages\PyInstaller\building\datastruct.py", line 184, in __postinit__

self.assemble()

File "D:\Anaconda3\envs\guanji\lib\site-packages\PyInstaller\building\build_main.py", line 590, in assemble

priority_scripts.append(self.graph.add_script(script))

File "D:\Anaconda3\envs\guanji\lib\site-packages\PyInstaller\depend\analysis.py", line 268, in add_script

self._top_script_node = super().add_script(pathname)

File "D:\Anaconda3\envs\guanji\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1345, in add_script

contents = fp.read() + '\n'

File "D:\Anaconda3\envs\guanji\lib\codecs.py", line 322, in decode

(result, consumed) = self._buffer_decode(data, self.errors, final)

**UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbd in position 4: invalid start byte**

问题出现的环境背景

使用anaconda创建了一个只包含需要库的环境,python版本是3.7,打包的文件编码方式是GB 2312

尝试过的解决方法

1.将文件在python的IDE中打开,在最上边,加注一行代码 # -- coding: utf-8 --
2.将python包目录下\PyInstaller\compat.py文件中
out = out.decode(encoding)
修改为:
out = out.decode(encoding, errors='ignore')
3.在打包的命令行中先输入chcp 65001 然后再输入打包命令。


回答:

可以试下nuitka打包

以上是 为什么python使用Pyinstaller打包成exe,只有spec文件? 的全部内容, 来源链接: utcz.com/p/939070.html

回到顶部