Python 2.7 : pyinstaller create qt.conf文件

标签 python qt pyqt exe pyinstaller

我正在使用以下命令创建 python 脚本 run.py 的 exe 文件:

pyinstaller.exe --noconsole --onefile  --icon=index.ico run.py

它在 dist 文件夹中创建一个 exe 文件,当我双击这个 exe 文件时,它还会生成一个 qt.conf 文件,其内容为:

[Paths]
Prefix = C:/Users/ANUBHA~1.JHA/AppData/Local/Temp/_MEI94~1/PyQt4
Binaries = C:/Users/ANUBHA~1.JHA/AppData/Local/Temp/_MEI94~1/PyQt4

如何阻止生成此 qt.conf 以及为什么生成它?

信息:

我的Python脚本run.py:

# -*- coding: utf-8 -*-
import PySimpleGUI27 as sg
import parse2
import UserList
import UserString

layout = [               
    [sg.Text('A2L File', size=(15, 1), auto_size_text=False, justification='right'),      
     sg.InputText('',key='_a2l_'), sg.FileBrowse(file_types=(("A2L File", "*.a2l"),))],
    [sg.Text('Signals Lexicon', size=(15, 1), auto_size_text=False, justification='right'),      
     sg.InputText('',key='_sigLex_'), sg.FileBrowse(file_types=(("Excel File", "*.xlsx"),))],
    [sg.Text('Parameters Lexicon', size=(15, 1), auto_size_text=False, justification='right'),      
     sg.InputText('',key='_parLex_'), sg.FileBrowse(file_types=(("Excel File", "*.xlsx"),))],
    [sg.Text('Module Name', size=(15, 1), auto_size_text=False, justification='right'),      
     sg.InputText('X',key='_module_'), sg.FolderBrowse()],           
    [sg.Submit(), sg.Cancel()],
    [sg.Output(size=(60, 20))]  
]
window = sg.Window('A2L Parser', default_element_size=(40, 1), icon=u'C:\\Users\\anubhav.jhalani\\Desktop\\index.ico').Layout(layout)

values_dict={}

if __name__ == '__main__':
    while True:
        button, values_dict = window.Read()
        if button=="Cancel" or button is None:
            break
        elif button=='Submit' and (not any(value == '' for value in values_dict.values())):   
            parse2.parser(values_dict['_a2l_'], values_dict['_sigLex_'], values_dict['_parLex_'],window)

        else:
            sg.Popup("Please select files")  

    window.Close()

和 pyinstaller 版本:3.4

最佳答案

qt.conf 文件似乎仅在使用普通 Python 或 WinPython 时创建。由于某种原因,使用 Anaconda Python 时似乎没有创建它。在 Pyinstaller 源中查找 qt.conf 不会给出任何结果。

作为解决方法,您可以在创建可执行文件后删除 qt.conf 文件

def remove_qt_temporary_files():
    if os.path.exists('qt.conf'):
        os.remove('qt.conf')

不删除

enter image description here

删除

enter image description here

示例。我不能 100% 确定 qt.conf 文件是在哪里创建的,但最后删除该文件似乎可行。

from PyQt4 import QtCore, QtGui 
import sys
import os

def remove_qt_temporary_files():
    if os.path.exists('qt.conf'):
        os.remove('qt.conf')

class ButtonGrid(QtGui.QWidget):
    def __init__(self, parent=None):
        super(ButtonGrid, self).__init__(parent)
        self.button_layout = QtGui.QGridLayout()

        for i in range(1,5):
            for j in range(1,5):
                self.button_layout.addWidget(QtGui.QPushButton("B"+str(i)+str(j)),i,j)

    def get_layout(self):
        return self.button_layout

if __name__ == '__main__':

    # Create main application window
    app = QtGui.QApplication([])
    app.setStyle(QtGui.QStyleFactory.create("Cleanlooks"))
    mw = QtGui.QMainWindow()
    mw.setWindowTitle('Remove qt.conf example')

    # Create button grid widget
    button_grid = ButtonGrid()

    # Create and set widget layout
    # Main widget container
    cw = QtGui.QWidget()
    ml = QtGui.QGridLayout()
    cw.setLayout(ml)
    mw.setCentralWidget(cw)

    ml.addLayout(button_grid.get_layout(),0,0)

    mw.show()
    remove_qt_temporary_files()

    if(sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()

关于Python 2.7 : pyinstaller create qt.conf文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56054825/

相关文章:

python - 在 txt 文件中找到关键字后,是否有更好的方法来验证字符串模式?

python - 连接 numpy 数组

python - 将 Mnist 数组数据转换为每个像素值的 one-hot 编码数组

c++ - QSpinBox 绘制不正确

c++ - 随机播放 QList 的部分内容

python - PyQt - 如何阅读文档

python - 关闭 QMessagebox 窗口后 PyQt 应用程序崩溃

python - 我可以在 Yed-Graphs 上使用 Python 的图算法吗?

c++ - 获取 block 设备的大小 Linux/Windows

python - pyQt 相当于 asyncore/asynchat