簡體   English   中英

嘗試運行 pyinstaller 創建的 .exe 文件時“執行腳本失敗”

[英]“Failed to execute script” when trying to run .exe file created by pyinstaller

我正在嘗試使用 pyinstaller 將我的 python 代碼編譯為 a.exe 文件。 使用以下代碼會生成一個沒有錯誤消息的可用.exe 文件:

from PyQt5 import QtCore, QtGui, QtWidgets
import sys
if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    window = QtWidgets.QMainWindow()
    window.show()
    print('app loaded')
    sys.exit(app.exec_())

但是,只要我添加:

from scipy.integrate import solve_ivp

對於導入語句,我收到錯誤消息“無法執行腳本”。 在命令 window 中執行 pyinstaller 期間,我還看到以下內容:“警告:無法找到 Qt5 翻譯”以及包括 Matplotlib 模塊在內的幾個警告。 我嘗試將PyQt5\Qt\plugins\platforms文件夾復制到保存 .exe 文件的文件夾中,並按照另一個問題中的建議將 Anaconda3\Library\plugins 添加為環境變量QT_PLUGIN_PATH ,但兩種建議的解決方案均無效。
當我嘗試從命令 window 執行程序時,我收到錯誤消息:“ImportError: DLL 加載失敗”
任何有關此問題的幫助將不勝感激。

編輯:
我嘗試了 oetzi 的提議,並專門為我的項目創建了一個新的 anaconda 環境。 我在新環境中安裝了 scipy、numpy、matplotlib 和 ZAA78521B1A35C1756A641AB7029 的模塊。 這次我在 Anaconda Prompt 中輸入了命令。 同樣,沒有 scipy.integrate.solve_ivp 它工作正常。 有了它,當我嘗試運行 pyinstaller 時出現以下錯誤。

18881 WARNING: Cannot read QLibraryInfo output: raised Expecting value: line 1 column 1 (char 0) when decoding:
False
Traceback (most recent call last):
  File "C:\Users\domin\Anaconda3\envs\testenv\Scripts\pyinstaller-script.py", line 10, in <module>
    sys.exit(run())
  File "C:\Users\domin\Anaconda3\envs\testenv\lib\site-packages\PyInstaller\__main__.py", line 111, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "C:\Users\domin\Anaconda3\envs\testenv\lib\site-packages\PyInstaller\__main__.py", line 63, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "C:\Users\domin\Anaconda3\envs\testenv\lib\site-packages\PyInstaller\building\build_main.py", line 844, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "C:\Users\domin\Anaconda3\envs\testenv\lib\site-packages\PyInstaller\building\build_main.py", line 791, in build
    exec(code, spec_namespace)
  File "C:\Users\domin\polybox\ETH\Master Thesis\PycharmProjects\Perfusion Simulation\Pyinstaller\test\test.spec", line 17, in <module>
    noarchive=False)
  File "C:\Users\domin\Anaconda3\envs\testenv\lib\site-packages\PyInstaller\building\build_main.py", line 243, in __init__
    self.__postinit__()
  File "C:\Users\domin\Anaconda3\envs\testenv\lib\site-packages\PyInstaller\building\datastruct.py", line 158, in __postinit__
    self.assemble()
  File "C:\Users\domin\Anaconda3\envs\testenv\lib\site-packages\PyInstaller\building\build_main.py", line 502, in assemble
    module_hook.post_graph()
  File "C:\Users\domin\Anaconda3\envs\testenv\lib\site-packages\PyInstaller\building\imphook.py", line 410, in post_graph
    self._load_hook_module()
  File "C:\Users\domin\Anaconda3\envs\testenv\lib\site-packages\PyInstaller\building\imphook.py", line 377, in _load_hook_module
    self.hook_module_name, self.hook_filename)
  File "C:\Users\domin\Anaconda3\envs\testenv\lib\site-packages\PyInstaller\compat.py", line 793, in importlib_load_source
    return mod_loader.load_module()
  File "<frozen importlib._bootstrap_external>", line 407, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 907, in load_module
  File "<frozen importlib._bootstrap_external>", line 732, in load_module
  File "<frozen importlib._bootstrap>", line 265, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 696, in _load
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\domin\Anaconda3\envs\testenv\lib\site-packages\PyInstaller\hooks\hook-PySide2.py", line 18, in <module>
    collect_system_data_files(pyside2_library_info.location['PrefixPath'],
  File "C:\Users\domin\Anaconda3\envs\testenv\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 87, in __getattr__
    return getattr(self, name)
  File "C:\Users\domin\Anaconda3\envs\testenv\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 89, in __getattr__
    raise AttributeError
AttributeError

好的,我現在所做的只是完全卸載並再次安裝所有內容。 之后我只添加了所需的模塊,它們是 scipy、numpy、matplotlib、Z5EAD0CD63EB9A6BBD44987266F。 之后,一切正常。 我的猜測是,因為我同時安裝了 PyQt5 和 PyQt4,所以它與模塊混淆了。 現在我只安裝了PyQt5,一切正常。

暫無
暫無

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

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