【问题标题】:After I convert PY to EXE using PyInstaller it throw error在我使用 PyInstaller 将 PY 转换为 EXE 后,它会抛出错误
【发布时间】:2021-09-26 09:34:10
【问题描述】:

在我将我的 PY 文件转换为 EXE 并运行它后,我收到了这个错误:

Traceback (most recent call last):
  File "PrngCipher.py", line 2, in <module>
    from kivy.app import App
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
  File "kivy\__init__.py", line 272, in <module>
  File "C:\Program Files\Python39\Lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_pkgutil.py", line 71, in _pyi_pkgutil_iter_modules
    assert pkg_path.startswith(SYS_PREFIX)
TypeError: startswith first arg must be str or a tuple of str, not PureWindowsPath

我是 Python 和 PyInstaller 的新手,我不知道这个错误是关于什么的,我遵循了许多教程并将正确的依赖项挂钩到 .spec 文件中,但它仍然坏了。 我的 .py、.kv 和 .spec 文件: https://drive.google.com/drive/folders/1F7I4xEphB3d2ErDPs7vGDpT7trTmHKgC?usp=sharing

【问题讨论】:

    标签: python kivy typeerror pyinstaller


    【解决方案1】:

    这是 PyInstaller 4.4 中的回归错误:[GitHub]: pyinstaller/pyinstaller - TypeError: startswith first arg must be a str or tuple of str, not PurePosixPath
    它已经修复(由 [GitHub]: pyinstaller/pyinstaller - hooks: pkgutil rthook: declare SYS_PREFIX as function-local symbol),但该修复将仅在下一个版本中可用,(考虑到错误的严重性)应该很快就会提供。

    走得更远:

    【讨论】:

    【解决方案2】:

    我做了更多的研究并查看了错误消息的上面几行,我发现问题出在 PyInstaller 包的代码而不是我的代码上,解决方法是将 PyInstaller 降级到 4.3 等待使用python -m pip install PyInstaller==4.3 和效果很好

    【讨论】:

      【解决方案3】:

      该错误告诉您您正在使用带有错误参数类型的startsWith,特别是,它希望String 作为第一个参数,而您传递PureWindowsPath。我不是 Python 专家,但我相信您可以通过为您要传递的变量调用 .__str__() 来解决它,因此它的值在传递给 startsWith 时将表示为 String

      【讨论】:

      • 我不知道startsWith 是什么,所以我无法真正调试它在我的代码中的哪一部分,不过感谢您简化了错误消息
      猜你喜欢
      • 2021-06-14
      • 1970-01-01
      • 1970-01-01
      • 2021-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多