24695 INFO: Building PYZ because PYZ-00.toc is non existent 24697 INFO: Building PYZ (ZlibArchive) C:\Users\SH2304020\Desktop\海康添加人员api v1.0\build\Add_person\PYZ-00.pyz 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\SH2304020\AppData\Local\Programs\Python\Python311\Scripts\pyinstaller.exe\__main__.py", line 7, in <module> File "C:\Users\SH2304020\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\__main__.py", line 194, in _console_script_run run() File "C:\Users\SH2304020\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\SH2304020\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\SH2304020\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\building\build_main.py", line 1030, in main build(specfile, distpath, workpath, clean_build) File "C:\Users\SH2304020\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\building\build_main.py", line 952, in build exec(code, spec_namespace) File "C:\Users\SH2304020\Desktop\海康添加人员api v1.0\Add_person.spec", line 22, in <module> pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\SH2304020\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\building\api.py", line 129, in __init__ self.__postinit__() File "C:\Users\SH2304020\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\building\datastruct.py", line 184, in __postinit__ self.assemble() File "C:\Users\SH2304020\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\building\api.py", line 149, in assemble self.code_dict[name] = get_code_object(name, src_path) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\SH2304020\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\building\utils.py", line 607, in get_code_object return compile(source, filename, 'exec') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: source code string cannot contain null bytes是什么问题
时间: 2023-07-05 14:32:42 浏览: 94
这个错误是由于源代码中包含了 null 字符(\x00)引起的。在 Python 中,null 字符在字符串中是不允许出现的,因为它会被解释为字符串的结束符。如果您的源代码中确实包含了 null 字符,那么您需要先去除这些 null 字符,然后再运行 PyInstaller。您可以使用文本编辑器或 Python 脚本来去除 null 字符。如果您使用的是文本编辑器,可以尝试使用“查找和替换”功能,将所有的 null 字符替换为空字符串。如果您使用的是 Python 脚本,可以使用以下代码来去除 null 字符:
```
with open('your_file.py', 'rb') as f:
data = f.read().replace(b'\x00', b'')
with open('your_file.py', 'wb') as f:
f.write(data)
```
这段代码会打开您的 Python 源代码文件,将其中的 null 字符替换为空字符串,然后将结果写回到原文件中。替换完成后,您可以再次运行 PyInstaller,应该就不会再出现这个错误了。
相关问题
Building PYZ because PYZ-00.toc is non existent
这是一个可能由于编译或打包过程中出现的错误,导致相关的文件或目录不存在,从而无法生成 PYZ 文件。您可以尝试重新编译或打包代码,并确保所有必要的文件和目录都存在。如果问题仍然存在,您可以检查编译或打包工具的配置,并查看是否存在任何缺失或错误的设置。另外,您也可以搜索类似的错误信息,查看其他开发者是如何处理这个问题的。
290103 INFO: Looking for eggs 290104 INFO: Using Python library C:\Users\GOD\AppData\Local\Programs\Python\Python310\python310.dll 290107 INFO: Found binding redirects: [] 290192 INFO: Warnings written to D:\work\chuanqi\build\main\warn-main.txt 291742 INFO: Graph cross-reference written to D:\work\chuanqi\build\main\xref-main.html 292930 INFO: checking PYZ 292931 INFO: Building PYZ because PYZ-00.toc is non existent 292932 INFO: Building PYZ (ZlibArchive) D:\work\chuanqi\build\main\PYZ-00.pyz 305821 INFO: Building PYZ (ZlibArchive) D:\work\chuanqi\build\main\PYZ-00.pyz completed successfully. 306174 INFO: checking PKG 306174 INFO: Building PKG because PKG-00.toc is non existent 306177 INFO: Building PKG (CArchive) main.pkg
这是一个关于Python程序打包的输出信息。在这个过程中,Python程序会被转换成一个独立的可执行文件,方便在其他机器上运行。在这个输出信息中,可以看到程序正在被打包成一个PYZ(Python Zip)文件和一个PKG(Package)文件。打包完成后,PYZ和PKG文件可以在其他机器上运行,而不需要安装Python环境。