[QGIS-Developer] why stop work python.exe in pyqgis standalone script anytime?
xristosss20
saxri89 at gmail.com
Sat Jul 8 17:31:54 PDT 2017
i want to create a simple standalone pyqgis script but i have some
Unexpectedly errors.
here my .bat file :
@echo off
SET OSGEO4W_ROOT=C:\OSGeo4W
call "%OSGEO4W_ROOT%"\bin\o4w_env.bat
call "%OSGEO4W_ROOT%"\apps\grass\grass-7.2.1\etc\env.bat
@echo off
path
%PATH%;%OSGEO4W_ROOT%\apps\qgis\bin;%OSGEO4W_ROOT%\apps\grass\grass-7.2.1\lib
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT:\=/%/apps/qgis
SET PYCHARM="C:\Program Files\JetBrains\PyCharm 2017.1.4\bin\pycharm.exe"
set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\qgis\python;
set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\Python27\Lib\site-packages;
set QGISPATH=%OSGEO4W_ROOT%\apps\qgis
start "PyCharm aware of QGIS" /B %PYCHARM% %*
first i try to see if processing tool work nice.
here the code :
def test1():
qgs = QgsApplication([],True)
QgsApplication.setPrefixPath("C:/OSGeo4W/apps/qgis", True)
qgs.initQgis()
sys.path.append('C:/OSGeo4W/apps/qgis/python/plugins')
import processing
from processing.core.Processing import Processing
Processing.initialize()
print processing.alglist()
qgs.exitQgis()
test1()
work fine i take the list correct
after i try to see if work algorithm where i want
here the code :
def slope():
qgs = QgsApplication([],True)
QgsApplication.setPrefixPath("C:/OSGeo4W/apps/qgis", True)
qgs.initQgis()
sys.path.append('C:/OSGeo4W/apps/qgis/python/plugins')
import processing
from processing.core.Processing import Processing
Processing.initialize()
print processing.alghelp('gdalogr:slope')
qgs.exitQgis()
slope()
and i take this message :
C:\OSGeo4W\bin\python.exe C:/Users/username/PycharmProjects/untitled/test.py
ALGORITHM: Slope
INPUT <ParameterRaster>
BAND <ParameterNumber>
COMPUTE_EDGES <ParameterBoolean>
ZEVENBERGEN <ParameterBoolean>
AS_PERCENT <ParameterBoolean>
SCALE <ParameterNumber>
OUTPUT <OutputRaster>
None
Process finished with exit code 0
but anytime to try to run some script with complete code like this :
from qgis.core import QgsApplication
import sys
from qgis.core import QgsRasterLayer
from PyQt4.QtCore import QFileInfo
def slope(raster_path,slope_path):
qgs = QgsApplication([],True)
QgsApplication.setPrefixPath("C:/OSGeo4W/apps/qgis", True)
qgs.initQgis()
sys.path.append('C:/OSGeo4W/apps/qgis/python/plugins')
import processing
from processing.core.Processing import Processing
Processing.initialize()
fileInfo=QFileInfo(raster_path)
baseName=fileInfo.baseName()
rLayer = QgsRasterLayer(fileInfo.filePath(), baseName)
processing.runalg('gdalogr:slope',rLayer,1.0,True,True,False,1.0,slope_path)
qgs.exitQgis()
raster_path="C:/Users/username/Desktop/dem.tif"
slope_path="C:/Users/username/Desktop/slope.tif"
slope(raster_path,slope_path)
then before finish script the python.exe stop running :
<http://osgeo-org.1560.x6.nabble.com/file/n5327125/pytho.jpg>
and i take this message in pycharm :
C:\OSGeo4W\bin\python.exe
C:/Users/username/PycharmProjects/untitled/test1.py
Process finished with exit code -1073741819 (0xC0000005)
that message i take for all scripts with different python code and specific
different algorithms if i want to run it standalone using pycharm editor.
any idea why python.exe stop work anytime ?
--
View this message in context: http://osgeo-org.1560.x6.nabble.com/why-stop-work-python-exe-in-pyqgis-standalone-script-anytime-tp5327125.html
Sent from the QGIS - Developer mailing list archive at Nabble.com.
More information about the QGIS-Developer
mailing list