PyInstaller "ValueError: source code string cannot contain null bytes" (ValueError: source code string cannot contain null bytes)

问题描述 投票:2回答:1

我得到了一个 ValueError: source code string cannot contain null bytes 执行命令时 pyinstaller main.py 的cmd中,无论是否有管理员权限。

Traceback (most recent call last):
  File "c:\users\User\appdata\local\programs\python\python38\lib\runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\User\appdata\local\programs\python\python38\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\User\AppData\Local\Programs\Python\Python38\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
  File "c:\users\User\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\__main__.py", line 114, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "c:\users\User\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\__main__.py", line 65, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "c:\users\User\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\build_main.py", line 734, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "c:\users\User\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\build_main.py", line 681, in build
    exec(code, spec_namespace)
  File "C:\Users\User\OneDrive\Pulpit\CODE\Python 3\PyGame Games\Game Of Pong\main.spec", line 30, in <module>
    coll = COLLECT(exe,
  File "c:\users\User\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\api.py", line 698, in __init__
    self.__postinit__()
  File "c:\users\User\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\datastruct.py", line 160, in __postinit__
    self.assemble()
  File "c:\users\User\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\api.py", line 732, in assemble
    fnm = checkCache(fnm, strip=self.strip_binaries,
  File "c:\users\User\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\utils.py", line 197, in checkCache
    cache_index = load_py_data_struct(cacheindexfn)
  File "c:\users\User\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\utils\misc.py", line 233, in load_py_data_struct
    return eval(f.read())
ValueError: source code string cannot contain null bytes

我试过用Notepad++删除代码中的NULL字符,也试过重新安装pyinstaller,但问题依然存在。

我能找到的唯一的解决办法是删除NULL字符,但是当我在Notepad++中用""(regex checked)替换"\x00 "时,没有任何内容被替换。

python pyinstaller valueerror
1个回答
0
投票

我想明白了。看来 pyinstaller 不兼容最新版本的 Python 3 (截至2020年5月24日)。我卸载了Python 3.8.3,安装了Python 3.7.7,安装了所有我在 main.py 并且成功了! 如此简单的解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.