[Qgis-user] "QgsProcessing" has no attribute 'run' (same for 'processing')

Johannes Kröger (WhereGroup) johannes.kroeger at wheregroup.com
Mon Mar 18 00:31:43 PDT 2024


Hi Zoltan,

the most important thing first: Don't fall into the "AI can program" 
mindset trap. You *will* end up with nonsense like this if you do. Those 
tools can often hallucinate non-existent APIs and mislead you. They 
might work for some more basic or wide-spread code bases but so far I 
have seen very bad results for PyQGIS. Best search the web using 
"pyqgis" as additional keyword to your query.

As https://qgis.org/pyqgis/3.34/core/QgsProcessing.html says, that class 
only contains data to be used by Processing things. It is not your entry 
point into using Processing via Python.

For that please see 
https://docs.qgis.org/3.34/en/docs/user_manual/processing/console.html , 
written by actual, smart humans ;)

And for the Batch file: Don't write your own, QGIS comes with a perfect 
one already, called |python-qgis[-ltr].bat| . See e.g. 
https://gis.stackexchange.com/a/428577/51035

Cheers and good luck!
Hannes

On 11.03.24 09:30, Zoltan Szecsei via QGIS-User wrote:
> Hi,
> Apologies for asking help on what hopefully might turn out to be 
> trivial, but I am pretty much blue in the face googling and asking 
> Gemini for help.
>
> There are 2 questions in this email:
>
> I have a Windows 11 OSGEO4W installation QGIS 3.36.0 and grass (and more).
> I use PyCharm 2023.3.4 (Community Edition) - but not yet configured 
> "nicely" for QGIS as I am mostly in a non-Open Source environment.
> Most of the stuff I write is python is for "problem fixes" and these 
> python scripts ideally run on a windows command-line with a BAT file.
>
> So, in this scenario below, I keep getting:       ..... *has no 
> attribute 'run'
> *This whether I am running inside PyCharm or on the command-line 
> through below batch job.
>
> *Question #1*
> *What is the correct bat file structure for running python scripts?*
> I currently have [below] but is it optimal?
>
>     SET QGIS_PATH=C:\OSGeo4W\apps\qgis
>     call "C:\OSGeo4W\bin\o4w_env.bat"
>     SET PYTHONPATH=%QGIS_PATH%\python;%PYTHONPATH%
>     SET PATH=%QGIS_PATH%\bin;%PATH%
>     C:\OSGeo4W\apps\Python39\python.exe
>     Z:\Projects\Development\python_QGIS\qgis_tests\qgisrun.py
>     pause
>
> *Question #2*
> I have tried many various import options, but I cannot get past the 
> *has no attribute 'run'*  error from python below code:
> Minimalst as this code is, it should run without adding anything else, 
> should it?
>
>     from qgis.core import QgsProcessing
>     shp_inErfPoly = 'Z:\\Erven_1February2024.shp'
>     shp_outErfFix = 'Z:\\Erven_1February2024_FixGeo.shp'
>     QgsProcessing.run("native:fixgeometries", { 'INPUT':
>     shp_inErfPoly, 'METHOD': 1,  'OUTPUT': shp_outErfFix})
>
>
>
> Some pointers on what to do or where to read would be great.
>
> Thanks in advance,
> Zoltan
>
>
>
>
> -- 
>
> =============================================
> Zoltan Szecsei GPrGISc 0031
> Director, Geograph (Pty) Ltd.
> GIS and Photogrammetric Services
>
> Cape Town, South Africa.
>
> Mobile: +27-83-6004028 (Signal, not WhatsApp)
>          +974-5058-8729
>          +36-20-4808362
>
> www.geograph.co.za
> =============================================
>
> _______________________________________________
> QGIS-User mailing list
> QGIS-User at lists.osgeo.org
> List info:https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe:https://lists.osgeo.org/mailman/listinfo/qgis-user

-- 
Johannes Kröger / GIS-Entwickler/-Berater

*********************************************
FOSSGIS Konferenz
20.-23. März 2024 in Hamburg
https://www.fossgis-konferenz.de/2024/

WhereGroup-Beiträge auf der FOSSGIS
https://wheregroup.com/unternehmen/aktuelles/
*********************************************

WhereGroup GmbH
c/o KK03 GmbH
Lange Reihe 29
20099 Hamburg
Germany

Tel: +49 (0)228 / 90 90 38 - 36
Fax: +49 (0)228 / 90 90 38 - 11

johannes.kroeger at wheregroup.com
www.wheregroup.com
Geschäftsführer:
Olaf Knopp, Peter Stamm
Amtsgericht Bonn, HRB 9885
-------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20240318/c5845fb2/attachment.htm>


More information about the QGIS-User mailing list