QGIS-Documentation
QGIS-Documentation copied to clipboard
Optimal way to import processing module?
In the documentation it says to import the processing module relative to the qgis module (which works), but a direct import seems to also work while not causing problems with language server implementations (at least for Jedi, which is the only one that has been found to work properly with qgis: https://gispo.fi/en/blog/cooking-with-gispo-qgis-plugin-development-in-vs-code/).
Page URL: https://docs.qgis.org/3.22/en/docs/user_manual/processing/console.html
[24.7.1. Calling algorithms from the Python console](https://docs.qgis.org/3.22/en/docs/user_manual/processing/console.html#id2)[](https://docs.qgis.org/3.22/en/docs/user_manual/processing/console.html#calling-algorithms-from-the-python-console)
The first thing you have to do is to import the processing functions with the following line:
from qgis import processing
Doing this, however, results in this linting error: "Module 'qgis.processing' has no 'run' member": pylint(no-member)
I happened to find that some users are simply writing:
import processing
and for whatever reason, the lint error goes away. (Example found in: https://gis.stackexchange.com/questions/421329/pyqgis-outside-gui-module-qgis-processing-has-no-attribute-run)
During program execution, both techniques work fine. Is there any reason to prefer one over the other? If not, should the recommendation be changed to the latter? At least this would enable QGIS Processing to play nicely with IDEs/linters.
@arimeyer For questions, you will get more chances in developer list than in this repository that has a lower traffic.
I agree that the behavior is really confusing.
Especially considering that the processing
module that is automatically imported in the QGIS Python Console is the import processing
one (2012 by Victor Olaya), not the one from from qgis import processing
(2018 by Nathan Woodrow). The linked documentation page is wrong in that one does not need to import manually.
@arimeyer did you ever ask this on the mailing list?
Thanks, @kannes . I didn't follow up with this, sorry. My contract that involved QGIS ended several months back, but I do hope you pursue it. I do think, however, that this is a documentation problem, and that rather than have such important information get lost on mail lists, those who know the answers should be revising the core docs.
Hello fellow QGIS scripters, @arimeyer , @kannes @DelazJ
I am at the same stage, wondering what I can do. importing processing regularly will load this
C:\Program Files\QGIS 3.30.0\apps\qgis\python\qgis\processing
containing algfactory.py which has no attribute "run"
However,
C:\Program Files\QGIS 3.30.0\apps\qgis\python\plugins\processing\ProcessingPlugin.py
contains runAlg (not exactly run)
How can I make it work?
Question for developers mail list.