6

I’ve been struggling since three days in a row to create a windows executable application from my python application. I have managed to get results but I’m not at all satisfied with the workarounds I did to make it work…

I am using qgis library and its Python 2.7 interpreter in which I was able to install the freezing tools. I used two different freezing tools : cx_Freeze and pyinstaller and I got the same errors.

To start building executable application with those tools I used a command prompt that I opened with this a bat file (OSGeo4W.bat) situated in « C:\QGIS ». When I have the build folder created with cx_Freeze (or the dist folder with pyinstaller) I always try to launche the executable application with a commend prompt without the previous environnement variable initialisation because I want a standalone application where the user doesn’t need to install qgis library on his computer.

  1. The first error I always get is :

    ImportError : No module named QtNetwork
    

    I do not need this module but for the sake of the application, I modified my python code and added the following line :

    from PyQt4 import QtNetwork
    

    I will then create a new .exe application and launch it again and I find other missing modules, at the end I changed my python code to :

    from PyQt4 import QtNetwork, QtXml, Qsci
    

    Finally I do not have any further missing module but I’m not sure that I realy solved the issue here… ?

  2. gdal folder:

    The second error I always get after "resolving" the import module issue is :

    ERROR 4 : Unable to open EPSG support file gcs.csv.
    Try setting the GDAL_DATA environment variable to point to the directory containing EPSG csv files.
    

    This seemed to be the same type of error than the previous one so I tried adding this code in my python code and I copied the gdal directory in my .exe application :

    gdal_prefix=str(cur_dir)+"\\gdal"
    os.environ["GDAL_DATA"] = gdal_prefix
    

    When I start the .exe application I still get the same error :

    ERROR 4 : Unable to open EPSG support file gcs.csv.
    Try setting the GDAL_DATA environment variable to point to the directory containing EPSG csv files.
    

    The only way I managed to find a workaround was to create a « Launch_app.bat » file with the following command :

    set GDAL_DATA=D:\tests\test_qgis_import\dist\App\gdal
    start App.exe
    

    At this point, the application works correctly but is very slow, does anyone have an idea how to resolve this last issue ?


My python code :

import os
import os.path
import sys
from untitled import *
from mapTools import *
from PyQt4 import QtNetwork, QtXml, Qsci

class Main(Ui_MainWindow, QtGui.QMainWindow):

    def __init__(self, parent=None):...

    def EditPolygon (self):...

if __name__ == '__main__':

    QgsApplication.initQgis()
    app = QApplication(sys.argv)

    app.processEvents()
    frame = Main()
    frame.show()
    frame.raise_()

app.exec_()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.