【问题标题】:when i run the exe i get No module named 'PyQt5' but from the script its work当我运行 exe 时,我得到 No module named 'PyQt5' 但从脚本中它的工作
【发布时间】:2020-04-07 23:05:08
【问题描述】:

我使用 Windows 10、python 3.7 和 pyinstaller 3.5 版。

我在 pycharm 中编写了一些脚本,当我点击运行(来自 pycharm IDE)时,它工作正常。

但是当我通过pyinstaller执行到exe(“pyinstaller --onefile design.py”)时,

我单击 dist 文件夹 (design.exe) 中的文件并收到此错误

Traceback (most recent call last):
  File "design21.py", line 10, in <module>
ModuleNotFoundError: No module named 'PyQt5'
[11116] Failed to execute script design21

我的代码以:

开头
    # -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'gui_with_layouts.ui'
#
# Created by: PyQt5 UI code generator 5.13.0
#
# WARNING! All changes made in this file will be lost!


from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QThread,pyqtSignal
from style import *
from firebase import firebase
import xlrd
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
import time
from PyQt5.QtWidgets import *


stop_flag = False

更新:

我不知道怎么做,但我做了下一步并且不知何故它起作用了:

  1. 删除第 10 行和第 11 行(导入“Pyqt5”)
  2. 执行新的exe(来自cmd推荐pyinstaller --onefile design21.py
  3. 从 dist 文件夹运行新的 exe 文件(当然我得到了错误,因为我使用了 moudle 'Pyqt5' 而没有导入它)。 4.再次添加导入行(我删除的行 10 和 11)。
  4. 再次执行新的exe(来自cmd的推荐pyinstaller --onefile design21.py) 然后当我运行新的exe时它工作...... 不知道为什么,但它起作用了。

【问题讨论】:

标签: python pyqt5 exe pyinstaller


【解决方案1】:

此处没有名为“PyQt5”的模块,不是 PyQt5 未在 python 环境中安装正确安装或使用正确的 python 环境。

Pycharm 编辑器转到项目设置并使用 'PyQt5' 选择 python 环境

或pycharm底部CMD安装pip install PyQt5

【讨论】:

  • 我确实通过 CMD 的 pip install 'PyQ5t' 正确安装了 'PyQt5'。
  • 遇到任何错误?
  • 没有错误。 moudle 'PyQ5t' 已成功安装,确切的证据是它在 pycharm IDE 中可以正常工作。
【解决方案2】:

您需要安装 pyqt5

只需打开 CMD 并安装它。

pip install pyqt5

【讨论】:

    【解决方案3】:

    我刚刚遇到了同样的问题。对我来说,在程序的第一行导入 sip 解决了这个问题:

    从 PyQt5 导入 sip

    【讨论】:

      猜你喜欢
      • 2017-10-18
      • 1970-01-01
      • 2020-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-22
      • 1970-01-01
      相关资源
      最近更新 更多