尝试使用“ pyinstaller <scriptname.py>”并得到“ TypeError:必须为整数(获取类型字节)”

时间:2019-09-25 10:03:08

标签: python python-3.x pyqt pyqt5 pyinstaller

我想通过python将一个简单的yes / no消息框创建为一个可执行文件。使用pyqt5并尝试使用pyinstaller.exe生成可执行文件。错误和错误

TypeError: an integer is required (got type bytes).

使用命令pyinstaller <scriptname.py>

之后
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QMessageBox , QDesktopWidget
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot

class App(QWidget):

    def __init__(self):
        super().__init__()
        self.initUI()

    def center(self):
        # geometry of the main window
        qr = self.frameGeometry()

        # center point of screen
        cp = QDesktopWidget().availableGeometry().center()

        # move rectangle's center point to screen's center point
        qr.moveCenter(cp)

        # top left of rectangle becomes top left of window centering it
        self.move(qr.topLeft())
    def initUI(self):

        self.center()

        buttonReply = QMessageBox.question(self, 'PyQt5 message', "Do you like PyQt5?",
                                           QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel, QMessageBox.Cancel)
        if buttonReply == QMessageBox.Yes:
            print('Yes clicked.')
        if buttonReply == QMessageBox.No:
            print('No clicked.')
        if buttonReply == QMessageBox.Cancel:
            print('Cancel')

        self.show()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec_())

2 个答案:

答案 0 :(得分:9)

我在某人的评论中找到了答案here

尝试使用与python 3.8兼容的最新版本。

pip install https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz

此解决方案对我有用

答案 1 :(得分:0)

PyInstaller 目前不支持 3.8。我建议您使用 3.7 或更早版本构建,直到支持 python 3.8