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 10:32:42 浏览: 138
Python库 | venv_kernel-1.0.0-py3-none-any.whl
这个错误是由于源代码中包含了 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,应该就不会再出现这个错误了。
阅读全文