When exporting a pyqt app with pyinstaller, an error occurs depending on the command

First of all, my English isn’t good, so I apologize with my grammar error

I have a problem with my PyQT5 app with Tensorflow CNN model.

when I export my app with this command “pyinstaller –onefile app.py”, I don’t have any problem.

But, when exporting my app with command “pyinstaller –onefile –windowed app.py”, error is occured.

error message is “‘NoneType’ object has no attribute ‘write'”

my source codes don’t have any ‘write’. I can’t understand error.

Below is my source code. plz check my code and solve my problem.

Thank you

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QPushButton, QVBoxLayout, QFileDialog, QHBoxLayout
from PyQt5.QtGui import QPixmap
from PyQt5.QtCore import Qt
from PIL import Image
import numpy as np
import tensorflow as tf
from tensorflow import keras
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'  # TensorFlow의 로그 레벨을 WARNING으로 설정


class EyeDiseaseClassifier(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()
        
    def initUI(self):
        self.setWindowTitle('반려견 안구 질환 예측기')
        
        self.layout = QVBoxLayout()
        
        self.uploadButton = QPushButton('이미지 업로드', self)
        self.uploadButton.clicked.connect(self.uploadImage)
        self.layout.addWidget(self.uploadButton)
        
        self.imageLabel = QLabel(self)
        self.imageLabel.setAlignment(Qt.AlignCenter)
        self.layout.addWidget(self.imageLabel)
        
        self.resultLabel = QLabel('예측 결과가 여기 표시됩니다.', self)
        self.resultLabel.setAlignment(Qt.AlignCenter)
        self.layout.addWidget(self.resultLabel)
        
        self.predictButton = QPushButton('검사하기', self)
        self.predictButton.clicked.connect(self.predict)
        self.layout.addWidget(self.predictButton)
        
        self.backButton = QPushButton('초기 화면으로 돌아가기', self)
        self.backButton.clicked.connect(self.reset)
        self.layout.addWidget(self.backButton)
        
        self.setLayout(self.layout)
        
        self.model = keras.models.load_model('best-cnn-model(ver1.0).h5')  # 모델 로드
        self.imagePath = None

    def uploadImage(self):
        options = QFileDialog.Options()
        options |= QFileDialog.ReadOnly
        fileName, _ = QFileDialog.getOpenFileName(self, "이미지 선택", "", "Images (*.png *.xpm *.jpg *.jpeg);;All Files (*)", options=options)
        if fileName:
            self.imagePath = fileName
            img = Image.open(fileName)
            img = img.convert('RGB')  # RGB 포맷으로 변환
            img = img.resize((128, 128))  # 크기 조정
            self.uploaded_image = np.array(img)  # 정규화하지 않고 배열로 변환
            pixmap = QPixmap(fileName)
            self.imageLabel.setPixmap(pixmap.scaled(400, 400, Qt.KeepAspectRatio))
            self.resultLabel.setText('')

    def predict(self):
        try:
            if self.imagePath:
                img = Image.open(self.imagePath)
                img = img.resize((128, 128))  # 모델의 입력 크기에 맞게 조정
                img = np.array(img)  # 정규화하지 않고 배열로 변환
                img = np.expand_dims(img, axis=0)
                prediction = self.model.predict(img)
                confidence = prediction[0][0]
                confidence_percentage = round(confidence * 100, 2)
                if confidence > 0.5:
                    self.resultLabel.setText(f"{confidence_percentage}% 확률로 안구 질환이 의심됩니다. {self.imagePath}")
                else:
                    self.resultLabel.setText(f"{100 - confidence_percentage}% 확률로 반려견의 눈이 건강하다고 예측됩니다. {self.imagePath}")
        except Exception as e:
            self.resultLabel.setText(f"예측 중 오류가 발생했습니다: {e}, n type(img): {type(img)}, type(self.model): {type(self.model)}, self.imagePath: {type(self.imagePath)}")
            

    def reset(self):
        self.imagePath = None
        self.imageLabel.clear()
        self.resultLabel.setText('예측 결과가 여기 표시됩니다.')

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

When there is no error, with command “pyinstaller –onefile app.py

When there is error, with command “pyinstaller –onefile –windowed app.py

adding except phrase.

New contributor

Dotorimuk is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật