[QGIS-Developer] PyQGIS standalone Python Scripts with pycharm - Loading the processsing.run() fails/nonexisting

Benjamin Jakimow benjamin.jakimow at geo.hu-berlin.de
Tue Jun 28 06:37:53 PDT 2022


Hi Michael,

you need to add the python\plugins folder to the pythonpath as well, 
either in your batch file or PyCharm

Greetings,

Benjamin

Am 28/06/2022 um 15:17 schrieb Egenolf, Michael via QGIS-Developer:
> Dear QGIS-Develeopers,
>
> I was trying to figure out how to get going with the processing modul in Pyqgis.
>   It seems that I am not able to load the processing tool properly.
>
> 1)
>
> I did make a bat file with the right pathes as followed:
>
> @echo off
> SET OSGEO4W_ROOT=C:\brk\programme\QGIS 3.16
> call %OSGEO4W_ROOT%\bin\o4w_env.bat
> call %OSGEO4W_ROOT%\apps\grass\grass78\etc\env.bat
>
> path %path%;%OSGEO4W_ROOT%\apps\qgis-ltr\bin
> path %path%;%OSGEO4W_ROOT%\apps\grass\grass78\lib
> path %path%;C:\OSGeo4W\apps\qt5\bin
> path %path%;C:\OSGeo4W\apps\Python37\Scripts
>
> set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\qgis\python
> set PYTHONHOME=%OSGEO4W_ROOT%\apps\Python37
>
> start "Pycharm aware of QGIS" /B "C:\brk\programme\PyCharm-Community_2021.3\bin\pycharm64.exe" %*
>
>
> 2)
>
> After that I am loading Pycharm and I am using  the following interpreter:
>
> C:\brk\programme\QGIS 3.16\bin\python-qgis-ltr.bat
>
> 3)
> This is my python code I want to run:
>
>
> from qgis import processing
>
> input = r'dein SHP Layer'
> outputWithLayer = 'memory '  # kannst den Layer lokal in einem Ordner speichern z.B. C:\test\shpfile.shp
>
>
> def buffer(input, outputWithLayer):
>      buffer_result = processing.run("native:buffer", {
>          'INPUT': input,
>          'DISTANCE': 10000,
>          # 'DISSOLVE': True,# Falls du alle Polygonen mergen willst
>          'OUTPUT': outputWithLayer
>      })
>
> bufferresult = buffer(input, outputWithLayer)
> print(bufferresult)
>
> # result_layer = buffer_result['OUTPUT']
> # layer = QgsVectorLayer(result_layer,"test","ogr")
> # QgsProject.instance().addMapLayer(layer)
>
>
>
> 4) Result
>
> Stil if I want to import processing as suggested everywhere there will always fail because the eather the modul is not importet or when I am using the buffer the run() method is not found:
>
>
> "C:\brk\programme\QGIS 3.16\bin\python-qgis-ltr.bat" C:/Users/Egenolf/AppData/Roaming/JetBrains/PyCharmCE2021.3/scratches/Test_Pyqt.py
> Traceback (most recent call last):
>    File "C:/Users/Egenolf/AppData/Roaming/JetBrains/PyCharmCE2021.3/scratches/Test_Pyqt.py", line 13, in <module>
>      import processing
> ModuleNotFoundError: No module named 'processing'
>
>
>
>
> Even after an intensive research on stackexchange/ GISstackexchange pages there is not clear solucion to this point or the solucion is not adapted to Python 3.
> Does anybody has a good loading script or some hints on how to solve this problem?
>
>
> Best regards
> Michael Egenolf
>
>
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info:https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe:https://lists.osgeo.org/mailman/listinfo/qgis-developer

-- 
Benjamin Jakimow, Doctoral Researcher
Earth Observation Lab | Geography Department | Humboldt-Universität zu Berlin

e-mail:benjamin.jakimow at geo.hu-berlin.de

phone:  +49 (0) 30 2093 6846
mobile: +49 (0) 157 5656 8477
fax:    +49 (0) 30 2093 6848
mail:   Unter den Linden 6 | 10099 Berlin | Germany
room: 2'211
web:https://hu-berlin.de/eo-lab
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20220628/a9d66d06/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: zRtAKFiY5K16hiJ6.png
Type: image/png
Size: 4367 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20220628/a9d66d06/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5457 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20220628/a9d66d06/attachment.bin>


More information about the QGIS-Developer mailing list