欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Python:pyinstaller 打包运行报错 failed to execute script ***

程序员文章站 2024-02-03 22:13:52
...

1、pyqt5 打包 exe 出现运行出现错误

pyinstaller -F -w +转化目标.py文件,生成exe
Python:pyinstaller 打包运行报错 failed to execute script ***

2、查看具体原因

pyinstaller -D +转化目标.py文件

然后cmd 切换 生成的 exe 目录, 命令开启程序
Python:pyinstaller 打包运行报错 failed to execute script ***

pyqt5 importError: unable to find Qt5Core.dll on PATH

3、解决方案

import sys, os
+ if hasattr(sys, 'frozen'):
+   os.environ['PATH'] = sys._MEIPASS + ";" + os.environ['PATH']
 
from PyQt5.QtWidgets import QMainWindow, QTextEdit, QApplication
from PyQt5.QtCore import QTimer

总的来说呢,就是有的版本pyqt5库对系统变量的加载存在bug,具体原因只有官方才能解释了,咱也没法管了,对有bug的版本库提供一种办法就是,在主程序中pyqt5库import之前就对系统变量进行手动设置