Python 2.7: pyinstaller создает файл qt.conf - PullRequest
1 голос
/ 09 мая 2019

Я использую приведенную ниже команду для создания exe-файла моего скрипта python run.py:

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

Он создает exe-файл в папке dist, и когда я дважды щелкаю по этому 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 и почему он генерируется?

Info :

Мой скрипт 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 Ответ

1 голос
/ 10 мая 2019

Файл qt.conf создается только при использовании стандартного Python или WinPython. По какой-то причине он не создается при использовании Anaconda Python. Подсказка для qt.conf в источнике Pyinstaller ничего не дает.

В качестве обходного пути вы можете просто удалить файл 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

* * Пример 1 022. Я не уверен на 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_()
...