Using Pycharm with QGIS 3
Asked Answered
O

1

6

I've installed QGIS 3.4 using the network installer (64 bit) and tried to use qgis with pycharm as described here: http://spatialgalaxy.net/2018/02/13/quick-guide-to-getting-started-with-pyqgis3-on-windows/

However, I can´t get the processing package to work properly in pycharm. For example, when I use a simple code like:

from qgis.core import *
import processing

processing.run("qgis:createpointslayerfromtable",
               {'INPUT':r'C:\Users\input.xlsx',
                'XFIELD':'GEO_X',
                'YFIELD':'GEO_Y',
                'ZFIELD':None,
                'MFIELD':None,
                'TARGET_CRS':QgsCoordinateReferenceSystem('EPSG:4326'),            
'OUTPUT':r'C:\Users\output.geojson'})

I get the error: Algorithm qgis:createpointslayerfromtable not found

The same code works when executed directly in the python window in QGIS so there must be a problem with my setup of pycharm.

As pyqgis.cmd I´m using:

@echo off
SET OSGEO4W_ROOT=C:\OSGeo4W64
call "%OSGEO4W_ROOT%"\bin\o4w_env.bat
call "%OSGEO4W_ROOT%"\apps\grass\grass-6.4.3\etc\env.bat
@echo off
path %PATH%;%OSGEO4W_ROOT%\apps\qgis\bin
path %PATH%;%OSGEO4W_ROOT%\apps\grass\grass-6.4.3\lib
path %PATH%;C:\OSGeo4W64\apps\Qt5\bin
path %PATH%;C:\OSGeo4W64\apps\Python37\Scripts

set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\qgis\python
set PYTHONHOME=%OSGEO4W_ROOT%\apps\Python37

start "PyCharm aware of Quantum GIS" /B "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.4\bin\pycharm.exe" %*

cmd.exe

I´ve tried different variants like adding CALL "%OSGEO4W_ROOT%"\etc\ini\python-core.bat

but nothing seems to work. Please help.

Outrageous answered 3/1, 2019 at 22:11 Comment(0)
D
0

I also had issues with this. Too many thing might go wrong, my current workflow is to code in IDE and then import the script in qgis to finish things.

The standalone processor shoulg be available (see https://github.com/qgis/QGIS/pull/34617)

To that effect you could use system/os.call to invoke it from your pycharm and use the processing tools this way. I haven't tried it yet but it should be simpler than fighting with paths and environment variables.

Dulcet answered 16/8, 2020 at 15:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.