2

I try to run standalone PyQgis code with PyCharm, but I always have this result :

Process finished with exit code -1073741819 (0xC0000005)

I tried my code line by line, and this result appear after the last :

from PyQt5.QtWidgets import QApplication, QFrame, QGridLayout, QMainWindow
from qgis.gui import QgsMapCanvas
from qgis.core import QgsApplication, QgsProject, QgsVectorLayer

app = QApplication([])
QgsApplication.setPrefixPath("C:/OSGeo4W64/apps/qgis", True)
QgsApplication.initQgis()

I use PyCharm 2018.3.6 (Community Edition), because issues on 2019 version occured. Qgis 3.6 with OSGeo4W.

My .cmd code :

@echo off
SET OSGEO4W_ROOT=C:\OSGeo4W64

@echo off
call "%OSGEO4W_ROOT%"\bin\o4w_env.bat
call "%OSGEO4W_ROOT%"\bin\qt5_env.bat
call "%OSGEO4W_ROOT%"\bin\py3_env.bat

@echo off
path %OSGEO4W_ROOT%\apps\qgis\bin;%PATH%
SET GDAL_FILENAME_IS_UTF8=YES

set VSI_CACHE=TRUE
set VSI_CACHE_SIZE=1000000
set QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\qgis\qtplugins;%OSGEO4W_ROOT%\apps\Qt5\plugins

SET PYCHARM="C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.6\bin\pycharm64.exe"

set PYTHONPATH=%OSGEO4W_ROOT%\apps\qgis\python
set PYTHONHOME=%OSGEO4W_ROOT%\apps\Python37
set PYTHONPATH=%OSGEO4W_ROOT%\apps\Python37\Lib\site-packages;%PYTHONPATH%

set QT_QPA_PLATFORM_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\Qt5\plugins\platforms
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT%\apps\qgis

start "PyCharm aware of QGIS" /B %PYCHARM%

Any ideas ?

1

Ok, I just replace

app = QApplication([])
QgsApplication.setPrefixPath("C:/OSGeo4W64/apps/qgis", True)
QgsApplication.initQgis()

by

app = QApplication([])
qgs = QgsApplication([],False)
qgs.setPrefixPath("C:/OSGeo4W64/apps/qgis", True)
qgs.initQgis()

It's work !

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.