I made an exe file from standalone application. However I want to enter the path variable on cmd when running the exe.
My standalone application running *.shp files. But I want to enter path of the *.shp files at the beginning, when I run the exe on cmd.
For instance my exe file name is myMap.exe and I want to do that:
C:\Users\Mustafa Uçar>cd C:\Users\Mustafa Uçar\Desktop\MyMap\build\exe.win-amd64-3.6
C:\Users\Mustafa Uçar\Desktop\MyMap\build\exe.win-amd64-3.6>myMap.exe C:\Users\Mustafa Uçar\Desktop\Tutorial\Mississippi\mississippi.shp
PyQt5 - Python 3.6 - Qgis 2.99
Here is my code (I give path of shapefile but I do not write it in script. I want to write it on cmd. Path variable must be changeable):
import sys
from qgis.core import *
from qgis.gui import *
from PyQt5.QtCore import *
from PyQt5 import QtGui
app = QgsApplication([], True)
path = "C:/OSGeo4W64/apps/qgis-dev"
app.setPrefixPath(path, True)
app.initQgis()
canvas = QgsMapCanvas()
title = "PyQGIS Standalone Application Example"
canvas.setWindowTitle(title)
canvas.setCanvasColor(Qt.white)
filepath = "C:/Users/Mustafa Uçar/Desktop/Tutorial/Mississippi/mississippi.shp"
layer = QgsVectorLayer(filepath, "testlayer", "ogr")
QgsProject.instance().addMapLayer(layer)
canvas.setExtent(layer.extent())
canvas.setLayers([layer])
canvas.zoomToFullExtent()
canvas.show()
sys.exit(app.exec_())