Python 2.7:pyinstaller创建qt.conf文件

时间:2019-05-09 08:02:55

标签: 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

1 个答案:

答案 0 :(得分:1)

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_()