簡體   English   中英

在我使用 PyInstaller 將 PY 轉換為 EXE 后,它會拋出錯誤

[英]After I convert PY to EXE using PyInstaller it throw error

在我將 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

我做了更多的研究並查看了錯誤消息的上面幾行,我發現問題出在 PyInstaller 包的代碼而不是我的代碼,解決方法是將 PyInstaller 降級到 4.3,等待使用python -m pip install PyInstaller==4.3進行修復python -m pip install PyInstaller==4.3 ,效果很好

該錯誤告訴您,您使用的是帶有錯誤參數類型的startsWith ,特別是它希望String作為第一個參數,而您則傳遞PureWindowsPath 我不是 Python 專家,但我相信您可以通過為要傳遞的變量調用.__str__()來解決它,因此它的值在傳遞給startsWith時將表示為String

這是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 ),但該修復將僅在下一個版本中可用,該版本(考慮到錯誤嚴重性)應該可用很快。

更進一步的方法:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM