【问题标题】:Pyinstaller: Failed to execute script pyi_rth_qt4pluginsPyinstaller:无法执行脚本 pyi_rth_qt4plugins
【发布时间】:2019-08-03 20:10:16
【问题描述】:

当我运行由 pyinstaller 创建的 .exe 时,它​​会显示如下屏幕截图所示的错误消息。

我使用 Python 3.6.4、pyinstaller 3.4 和 PyQt5 5.12 在 Windows 10 中制作我的 GUI 程序。为什么在运行 .exe 时 .exe 需要 PySide 模块和 PyQt4?我不明白。 .py 可以运行,没有任何错误。

实际上,在我收到此错误之前,我在生成 exe 的过程中遇到了错误Exception:Cannot find PyQt4 plugin directories,但我认为我不需要 PyQt4,所以我将其卸载。然后 pyinstaller 进程继续进行,直到出现新错误。

Exception:
Cannot find existing PyQt5 plugin directories
Paths checked: C:/qt64/qt_1544645195969/_h_env/Library/plugins

我通过将pyqt5qmlplugin.dll复制到上面提到的路径C:/qt64/qt_1544645195969/_h_env/Library/plugins解决了这个问题。最后我得到了 .exe,但不幸的是我仍然得到了屏幕截图中显示的错误,我无法使用 pip 安装 PyQt4。它报告:

Could not find a version that satisfies the requirement PyQt4 (from versions: )  
No matching distribution found for PyQt4

我也无法安装 PySide,因为 only these Python versions are supported: [(2.6), (2.7), (3.2), (3.3), (3.4)]

【问题讨论】:

    标签: python pyqt5 pyside pyinstaller


    【解决方案1】:

    对我有用的是使用 Python 3.5 创建一个新环境并在其中安装脚本所需的所有库。 如果您使用的是 Anaconda,请按照以下步骤操作:

    conda create yourenvironmentname python=3.5

    conda 激活你的环境名称

    将“yourenvironmentname”替换为您想要的环境名称。

    如果不使用 Anaconda:

    pipenv --python 3.5

    如果它不起作用,请改用 python 3.4 尝试。

    【讨论】:

    • 对不起,它对我不起作用。而且我不认为错误是由python版本引起的。
    • 我可以用 pyinstaller 以同样的方式成功传输一些 .py 程序。但是截图中提到的程序总是失败。在使用命令 pyinstaller 运行期间,总是缺少一些模块。是这个原因吗?
    • 请确保将您导入的所有模块安装到您创建的环境中的代码中,否则将无法正常运行。如果仅支持提到的 Python 版本,请尝试从安装了 Python 3.4 的环境中运行 Pyinstaller。
    【解决方案2】:

    这个问题是安装程序正在识别 pyqt4。要解决此问题,请执行以下操作:

    1. 转到 “\Lib\site-packages\PyInstaller\loader\rthooks\pyi_rth_qt4plugins.py”。
    2. 注释掉所有内容。
    3. 完成后,重新运行pyinstaller

      它应该可以工作。祝你好运。

    【讨论】:

      【解决方案3】:

      如果您在您的程序中使用 PyQt5,请继续在以下目录中的“pyi_rth_qt4plugins.py”文件:Local\Continuum\anaconda3\Lib\site-packages\PyInstaller\loader\rthooks.

      替换

      1. PySide.QtCorePySide2.QtCore
      2. PyQt4.QtCore import QCoreApplicationPyQt5.QtCore import QCoreApplication

      我尝试通过注释文件来遵循上面的步骤,但直到我这样做才起作用。

      【讨论】:

      • 仅供参考。对于 PyInstaller 4.0,rthooks 文件夹现在放置在钩子下,而不是加载器下
      猜你喜欢
      • 1970-01-01
      • 2021-03-28
      • 2021-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-30
      • 2021-02-14
      • 2017-02-25
      相关资源
      最近更新 更多