【问题标题】:Python 2.7 : pyinstaller create qt.conf filePython 2.7:pyinstaller 创建 qt.conf 文件
【发布时间】:2019-09-27 00:26:55
【问题描述】:

我正在使用以下命令来创建我的 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

【问题讨论】:

    标签: python qt pyqt exe pyinstaller


    【解决方案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')
    

    不删除

    删除

    示例。我不能 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_()
    

    【讨论】:

    • 你把这段代码放在哪里?因为 qt.conf 在双击 exe 文件后生成
    猜你喜欢
    • 2019-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-18
    • 2017-10-09
    • 2016-09-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多