我使用PyInstaller将PY转换为EXE后,出现了错误。

3
在我将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
3个回答

1
我进行了更多的研究并查看了错误信息的上面几行,发现问题出在PyInstaller软件包的代码上,而不是我的代码,解决方法是将PyInstaller降级到4.3版本,等待修复。您只需要执行以下命令:python -m pip install PyInstaller==4.3就可以了,这样就可以正常工作了。

0
错误告诉您正在使用错误的参数类型调用 startsWith,特别是它期望第一个参数是一个 String,而您实际传递的是 PureWindowsPath。我不是 Python 专家,但我相信您可以通过调用要传递的变量的 .__str__() 方法来解决此问题,这样其值在被传递到 startsWith 时将被表示为 String

我不知道什么是 startsWith,所以我无法真正调试我的代码中的哪个部分出了问题,但感谢您简化了错误信息。 - SilencedFrost

0

这是一个关于编程的回归错误,出现在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),但修复只会在下一个版本中发布,考虑到错误的严重性,下一个版本应该很快就会发布。

进一步探索的方法:


将答案从 https://stackoverflow.com/questions/68562958/typeerror-in-opening-an-exe-file 移动。 - CristiFati

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接