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 ?

Zacharie Moulin
  • 339
  • 1
  • 11
  • Maybe this will help you setting up your pycharm env: https://gis.stackexchange.com/questions/251851/using-pycharm-with-qgis-3 – zwnk Jun 20 '19 at 12:53

1 Answers1

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 !

Zacharie Moulin
  • 339
  • 1
  • 11