所以,我有两个.py文件,一个由Qt设计器 http://pyqt.sourceforge.net/Docs/PyQt4/designer.html另一个基本上实现了 GUI 的功能。使用,py安装程序 https://pyinstaller.readthedocs.io/en/stable/index.html,我生成了一个.exe文件以在没有 python 和相关库的系统上使用它。
命令:pyinstaller my_script.py
运行良好,没有任何错误。
当我运行时出现问题.exe file.
Error:
Qt:检测到未经测试的 Windows 版本 10.0!
回溯(最近一次调用最后一次):
文件“site-packages\PyInstaller\loader\rthooks\pyi_rth_qt4plugins.py”,第 41 行,位于
导入错误:没有名为“PySide”的模块
在处理上述异常的过程中,又出现了一个异常:
回溯(最近一次调用最后一次):
文件“site-packages\PyInstaller\loader\rthooks\pyi_rth_qt4plugins.py”,第 43 行,位于
文件“”,第 2237 行,位于 _find_and_load 中
文件“”,第 2226 行,在 _find_and_load_unlocked 中
文件“”,第 1191 行,在 _load_unlocked 中
文件“”,第 1161 行,位于 _load_backward_complete 中
文件“C:\python\lib\site-packages\PyInstaller\loader\pyimod03_importers.py”,第 714 行,在 load_module 中
module = loader.load_module(全名)
RuntimeError:PyQt4.QtCore 和 PyQt5.QtCore 模块都包装 QObject 类
[11364] 无法执行脚本 pyi_rth_qt4plugins
所以我试图找到解决这个问题的方法。这些是我尝试过的解决方案:
如何强制 PyQt5 用于 QObject 类? https://stackoverflow.com/questions/30697089/how-to-force-pyqt5-use-for-qobject-class- 只需使PyQt
import 因为第一个语句不能解决问题。
https://github.com/tzutalin/labelImg/issues/268 https://github.com/tzutalin/labelImg/issues/268- 这里建议删除PyQt4 and use only PyQt5。我的系统上确实有这两个,有些项目依赖于PyQt5还有一些关于PyQt4因此我不想删除后者。还,必须有另一个解决方案,让我不这样做。
https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000551170-PyQt4-and-PyQt5-collisions-in-PyCharm-2017-2-1-when-debugging-QGIS-application https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000551170-PyQt4-and-PyQt5-collisions-in-PyCharm-2017-2-1-when-debugging-QGIS-application- 这是一个类似的错误,所以我添加了:
matplotlib.rcParams['backend'] = 'Qt4Agg'
matplotlib.rcParams['backend.qt4'] = 'PyQt4'
对于我的进口,仍然不起作用。
Note:我在用:
PyCharm 2018.1(社区版)
内部版本 #PC-181.4203.547,建于 2018 年 3 月 26 日
JRE:1.8.0_152-release-1136-b20 amd64
JVM:JetBrains s.r.o 的 OpenJDK 64 位服务器 VM
Windows 10 10.0
并且代码在 IDE 中运行良好。
EDIT:
我的进口是:
from PyQt4 import QtCore, QtGui
from matplotlib.backends.backend_qt4agg import FigureCanvasQTagg as Canvas
我没有添加任何其他与 Qt 相关的导入语句。
EDIT - 2:
Trying CX_冻结代替py安装程序,这是安装文件。
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == "win32":
base = "Win32GUI"
additional_mods = ['numpy.core._methods', 'numpy.lib.format',
'numpy._distributor_init']
setup( name="ASCII2fig",
version = "0.1",
description = "GUI",
options = {'build_exe': {'includes': additional_mods}},
executables = [Executable("ASCII2figALL_main_edited.py", base=base)])
我添加了additional_mods
执行脚本一次后ImportError
,不间断。有什么方法可以破解并找到我应该明确提及的库吗?
此外,我还尝试检查哪些图书馆当我使用 Qt 运行主脚本时,它们实际上被导入:
from modulefinder import ModuleFinder
filename = "ASCII2figALL_main_edited.py"
finder = ModuleFinder()
finder.run_script(filename)
for name, mod in finder.modules.items():
print(name)
显然,它正在导入 PyQt5内部。正如之前提到的,我有NO提及 PyQt5 的导入语句。
Edit - 3
所以,我将代码更改为pure PyQt5,更新了py安装程序到最新版本 - 3.4,现在有一个新问题,找不到 Qt 插件。它仍然以某种方式导入 PyQt4,但我不知道在哪里。