[QGIS-Developer] Problem with creating EXE aplikation PyQGIS

office at kanet.sk office at kanet.sk
Mon Mar 20 02:53:53 PDT 2023


 

I using Python Interpreter C:\OSGeo4W\apps\Python39\python.exe and QGis 3.22
and IDE Pycharm 2022.2.2

 

 

Kind regards / Spozdravom 

************************************
Ing. Stanislav Klanduch 
firm owner

KAnet soft-net services
Kuzmányho 902 
01701 Považská Bystrica
Slovakia (SK)

tel:         +421 6504 07170
mobil:   +421 918 394 876
fax:        +421 6504 07170
mail:       <mailto:office at kanet.sk> office at kanet.sk 

web:       <http://www.kanet.sk> www.kanet.sk 
************************************

P Pred vytlacením tohto mailu prosím zvážte dopad na životné prostredie.
Dakujeme. / Please consider the environment before printing this e-mail.
Thanks. 

 

 

 

From: office at kanet.sk <office at kanet.sk> 
Sent: Monday, March 20, 2023 10:50 AM
To: 'qgis-developer at lists.osgeo.org' <qgis-developer at lists.osgeo.org>
Subject: Problem with creating EXE aplikation PyQGIS

 

Hallo, 

 

I have a larger application, just this small test, I'm trying pyinstaller.

I am testing a simple PyQgis application. When I add the line "from
qgis.core import QgsApplication" and make an exe via pyinstaller, the
application crashes with an error:

When I comment out the line "from qgis.core import QgsApplication" the
application window starts normally after creating the EXE.

 

See Code: 

 

import sys

 

from qgis.PyQt.QtWidgets import QApplication, QMainWindow, QWidget,
QHBoxLayout, QLabel

from qgis.core import QgsApplication

 

class MainWindow(QMainWindow):

    def __init__(self, parent=None):

        super(MainWindow, self).__init__(parent)

        self.setWindowTitle("Mapová prezeračka ---  Pebieha načítanie dát
...")

        self.init_gui()

        self.show()

 

    def init_gui(self):

        self.formular = QWidget()

        layoutFormulara = QHBoxLayout()

        self.formular.setLayout(layoutFormulara)

        boxLayout1 = QHBoxLayout()

        boxLayout2 = QHBoxLayout()

 

        layoutFormulara.addStretch()

        layoutFormulara.addLayout(boxLayout1)

        layoutFormulara.addLayout(boxLayout2)

        layoutFormulara.addStretch()

 

        self.label1 = QLabel("Hello")

        boxLayout1.addWidget(self.label1)

        self.setCentralWidget(self.formular)

 

 

def main():

    # vytvoriť hlavné okno

    mainWin = MainWindow()

    mainWin.show()

 

    # Run aplikáciu

    try:

        retval = app.exec_()

        # Exit aplication

        sys.exit(retval)  # this will always trigger SystemExit

    except SystemExit:

        print("sys.exit() it worked as expected ")

    except:

        print("Something has gone terribly wrong ")  # another exception was
raised

 

 

if __name__ == "__main__":

    app = QApplication(sys.argv)

    main()

 

 

I looked for many answers on the Internet but I couldn't find anything.
I've read the pyinstaller manual, I'm just new to this. I am sending a
TestEXE.spec file.

 

Pripájam file spec. 

 

import os
block_cipher = None
workdir = os.getenv('VIEWER_DIR')
a = Analysis(['main.py'],
         pathex=[workdir],
         binaries=None,
         datas=[(os.path.join(workdir,'testdata/*'),'testdata'),
                (os.path.join(workdir,'qgis_plugins/*'),'qgis_plugins'),
                (os.path.join(workdir,'graphics/*'),'graphics'),],
         hiddenimports=['qgis.PyQt.QtWidgets','qgis.core.QgsApplication']
         hookspath=None,
         runtime_hooks=None,
         excludes=None,
         win_no_prefer_redirects=None,
         win_private_assemblies=None,
         cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
         cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name='TestEXE',
          debug=True,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=False ,
          icon='graphics/airports.ico')
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               upx_exclude=[],
               name='TestEXE')

 

 

Thank you very much in advance for your help.

 

 

Kind regards / Spozdravom 

************************************
Ing. Stanislav Klanduch 
firm owner

KAnet soft-net services
Kuzmányho 902 
01701 Považská Bystrica
Slovakia (SK)

tel:         +421 6504 07170
mobil:   +421 918 394 876
fax:        +421 6504 07170
mail:       <mailto:office at kanet.sk> office at kanet.sk 

web:       <http://www.kanet.sk> www.kanet.sk 
************************************

P Pred vytlacením tohto mailu prosím zvážte dopad na životné prostredie.
Dakujeme. / Please consider the environment before printing this e-mail.
Thanks. 

 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20230320/d7dc8afc/attachment-0003.htm>


More information about the QGIS-Developer mailing list