简体   繁体   English

尝试运行 pyinstaller 创建的 .exe 文件时“执行脚本失败”

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

I am trying to compile my python code to a.exe file using pyinstaller.我正在尝试使用 pyinstaller 将我的 python 代码编译为 a.exe 文件。 Using the following code yields a usable.exe file with no error messages:使用以下代码会生成一个没有错误消息的可用.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_())

However, as soon as I add:但是,只要我添加:

from scipy.integrate import solve_ivp

to the import statements, I get the error message "Failed to execute script".对于导入语句,我收到错误消息“无法执行脚本”。 During execution of pyinstaller in the command window i also see the following: "WARNING: Unable to find Qt5 translations" plus several warnings including the Matplotlib module.在命令 window 中执行 pyinstaller 期间,我还看到以下内容:“警告:无法找到 Qt5 翻译”以及包括 Matplotlib 模块在内的几个警告。 I tried copying the PyQt5\Qt\plugins\platforms folder to the folder holding the.exe file and adding Anaconda3\Library\plugins as environment variable QT_PLUGIN_PATH as suggested in another question, but both proposed solutions did not work.我尝试将PyQt5\Qt\plugins\platforms文件夹复制到保存 .exe 文件的文件夹中,并按照另一个问题中的建议将 Anaconda3\Library\plugins 添加为环境变量QT_PLUGIN_PATH ,但两种建议的解决方案均无效。
When I try to execute the program from the command window I get the error message: "ImportError: DLL load failed"当我尝试从命令 window 执行程序时,我收到错误消息:“ImportError: DLL 加载失败”
Any help with this problem would be greatly appreciated.任何有关此问题的帮助将不胜感激。

Edit:编辑:
I tried oetzi's proposition and created a new anaconda environment specifically for my project.我尝试了 oetzi 的提议,并专门为我的项目创建了一个新的 anaconda 环境。 I installed the modules of scipy, numpy, matplotlib, and pyqt and installed pyinstaller in that new environment.我在新环境中安装了 scipy、numpy、matplotlib 和 ZAA78521B1A35C1756A641AB7029 的模块。 This time I typed the commands in the Anaconda Prompt.这次我在 Anaconda Prompt 中输入了命令。 Again, without scipy.integrate.solve_ivp it works fine.同样,没有 scipy.integrate.solve_ivp 它工作正常。 With it, I get the following error when i try to run pyinstaller.有了它,当我尝试运行 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

Okay what I now did was to just completely uninstall and install everything again.好的,我现在所做的只是完全卸载并再次安装所有内容。 Afterwards I only added the required modules which were scipy, numpy, matplotlib, pyqt5 and pyinstaller.之后我只添加了所需的模块,它们是 scipy、numpy、matplotlib、Z5EAD0CD63EB9A6BBD44987266F。 After that, everything worked fine.之后,一切正常。 My guess is, that since I had both, PyQt5 and PyQt4 installed, it messed with the modules.我的猜测是,因为我同时安装了 PyQt5 和 PyQt4,所以它与模块混淆了。 Now that I only installed PyQt5, everything is okay.现在我只安装了PyQt5,一切正常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用pyinstaller创建的exe无法执行 - exe created with pyinstaller failed to execute Pyinstaller exe执行脚本失败 - Pyinstaller exe failed to execute script Pyinstaller - “致命错误! 将脚本转换为 exe 时无法执行脚本” - Pyinstaller - “Fatal error ! Failed to execute script” when converting script to exe Pyinstaller - Python exe 运行时显示错误“无法执行脚本 pyi_rth_nltk” - Pyinstaller - Python exe when run shows error “Failed to execute script pyi_rth_nltk” 由于未处理的异常,Pyinstaller exe 文件无法执行脚本 - Pyinstaller exe file failed to execute script due to unhandled exception Pyinstaller 不会将 pkg 导入 exe 文件/无法执行脚本 - Pyinstaller wont import a pkg into the exe file / failed to execute the script 使用 pyinstaller 创建的 .exe 文件在我运行时立即关闭 - .exe file created with pyinstaller shuts down immediately when i run it 使用 pyinstaller 转换为 .exe 后退出 pygame 窗口而未打开控制台时出现“无法执行脚本 myscript” - "Failed to execute script myscript" when exiting pygame window without console open after converting to .exe with pyinstaller python PyInstaller创建的可执行文件无法运行exe错误:找不到Temp \\\\ _ MEI175682(数据文件) - python PyInstaller created executable failed to run the exe Error: cannot find Temp\\_MEI175682 (data file) Kivy 使用 PyInstaller 执行。 [Failed to execute script main] 因为 SoundLoader - Kivy to Exe with PyInstaller. [Failed to execute script main] because of SoundLoader
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM