[QGIS-Developer] QGIS-Developer Digest, Vol 200, Issue 33

Egenolf, Michael michael.egenolf at bezreg-koeln.nrw.de
Tue Jun 28 22:14:59 PDT 2022


Thank you Benjamin,

I addapted the batch file with the python path:

set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\qgis\python;%OSGEO4W_ROOT%\apps\qgis-ltr\python\plugins

I hope this is correct? At least the geoprocessing libary is loading...

Now I am geeting the following error:

1) Code:

import qgis.core
from qgis import processing


#### try sys.path.extend()

input = r'C:\test\input.shp'
outputWithLayer = r'C:\test\result.shp '  # 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)

2) result

Traceback (most recent call last):
  File "C:/Users/Egenolf/AppData/Roaming/JetBrains/PyCharmCE2021.3/scratches/Test_Pyqt.py", line 21, in <module>
    bufferresult = buffer(input, outputWithLayer)
  File "C:/Users/Egenolf/AppData/Roaming/JetBrains/PyCharmCE2021.3/scratches/Test_Pyqt.py", line 13, in buffer
    buffer_result = processing.run("native:buffer", {
AttributeError: module 'qgis.processing' has no attribute 'run'

Process finished with exit code 1

Where can I find the run method or how do I use the native:buffer otherwise

Regards
Michael

-----Ursprüngliche Nachricht-----
Von: QGIS-Developer <qgis-developer-bounces at lists.osgeo.org> Im Auftrag von qgis-developer-request at lists.osgeo.org
Gesendet: Dienstag, 28. Juni 2022 17:50
An: qgis-developer at lists.osgeo.org
Betreff: QGIS-Developer Digest, Vol 200, Issue 33

Send QGIS-Developer mailing list submissions to
	qgis-developer at lists.osgeo.org

To subscribe or unsubscribe via the World Wide Web, visit
	https://lists.osgeo.org/mailman/listinfo/qgis-developer
or, via email, send a message with subject or body 'help' to
	qgis-developer-request at lists.osgeo.org

You can reach the person managing the list at
	qgis-developer-owner at lists.osgeo.org

When replying, please edit your Subject line so it is more specific than "Re: Contents of QGIS-Developer digest..."


Today's Topics:

   1. Re: PyQGIS standalone Python Scripts with pycharm - Loading
      the processsing.run() fails/nonexisting (Benjamin Jakimow)
   2. Problems building QGIS 3.26 using Python 3.10.5 and SIP 6.6.2
      (Hern?n De Angelis)


----------------------------------------------------------------------

Message: 1
Date: Tue, 28 Jun 2022 15:37:53 +0200
From: Benjamin Jakimow <benjamin.jakimow at geo.hu-berlin.de>
To: qgis-developer at lists.osgeo.org
Subject: Re: [QGIS-Developer] PyQGIS standalone Python Scripts with
	pycharm - Loading the processsing.run() fails/nonexisting
Message-ID: <bc38343f-98df-3f69-62ae-2d8502d2cde9 at geo.hu-berlin.de>
Content-Type: text/plain; charset="utf-8"; Format="flowed"

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/T
> est_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://smex-ctp.trendmicro.com:443/wis/clicktime/v1/query?url=https%3a%2f%2fhu%2dberlin.de%2feo%2dlab&umid=fc901b20-44de-4224-b713-e1d99e20eb3c&auth=c1c9dbefcde83ed9c8881a36adbd110cc362e9ce-344615b2f04abba6045c7a9855d90df37e53bdc2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20220628/a9d66d06/attachment-0001.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-0001.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-0001.bin>

------------------------------

Message: 2
Date: Tue, 28 Jun 2022 17:50:12 +0200
From: Hern?n De Angelis <variablestarlight at gmail.com>
To: qgis-developer <qgis-developer at lists.osgeo.org>
Subject: [QGIS-Developer] Problems building QGIS 3.26 using Python
	3.10.5 and SIP 6.6.2
Message-ID: <5627189b-416e-2dbb-6ee8-ce49c41967d6 at gmail.com>
Content-Type: text/plain; charset="utf-8"; Format="flowed"

Hi developers,

I am trying to understand some errors I get while building either QGIS
3.26 or the latest main branch from GitHub in openSUSE Tumbleweed. I normally compile the latest source every few weeks and normally things go fine. Last few times I compiled Python was 3.8 and 3.9 and there were no problems. However, recently this distribution I use has made Python3 = 3.10.5. SIP is 6.6.2. To my knowledge all other dependencies are satisfied. I wonder if the change in Python or SIP versions may have introduced some known incompatibility. Errors are listed below. Any hint is appreciated.

Thanks in advance

/H.

sip-build: An internal error occurred...
Traceback (most recent call last):
 ? File "/bin/sip-build", line 33, in <module>  ??? sys.exit(load_entry_point('sip==6.6.2', 'console_scripts',
'sip-build')())
 ? File "/usr/lib64/python3.10/site-packages/sipbuild/tools/build.py",
line 37, in main
 ??? handle_exception(e)
 ? File "/usr/lib64/python3.10/site-packages/sipbuild/exceptions.py",
line 81, in handle_exception
 ??? raise e
 ? File "/usr/lib64/python3.10/site-packages/sipbuild/tools/build.py",
line 34, in main
 ??? project.build()
 ? File "/usr/lib64/python3.10/site-packages/sipbuild/project.py", line 244, in build  ??? self.builder.build()  ? File "/usr/lib64/python3.10/site-packages/sipbuild/builder.py", line 48, in build  ??? self._generate_bindings()  ? File "/usr/lib64/python3.10/site-packages/sipbuild/builder.py", line 277, in _generate_bindings  ??? buildable = bindings.generate()  ? File "/usr/lib64/python3.10/site-packages/sipbuild/bindings.py", line 166, in generate  ??? spec, sip_files = parse(self.sip_file, SIP_VERSION, encoding,  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/parser.py",
line 35, in parse
 ??? protected_is_public, include_dirs, strict).parse(sip_file)  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/parser_manager.py",
line 1507, in parse
 ??? self._parser.parse(self._read(sip_file, raw_sip_file),  ? File "/usr/lib/python3.10/site-packages/ply/yacc.py", line 331, in parse  ??? return self.parseopt(input, lexer, debug, tracking, tokenfunc)  ? File "/usr/lib/python3.10/site-packages/ply/yacc.py", line 823, in parseopt  ??? p.callable(pslice)  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/rules.py",
line 3029, in p_typedef_decl
 ??? instantiated = pm.instantiate_class_template(p, name_symbol,  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/parser_manager.py",
line 1480, in instantiate_class_template  ??? instantiate_class(p, symbol, fq_cpp_name, tmpl_names, proto_class,  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/instantiations.py",
line 131, in instantiate_class
 ??? i_class.ctors = _instantiate_ctors(tmpl_names, proto_class, template,  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/instantiations.py",
line 235, in _instantiate_ctors
 ??? i_ctor.py_signature = _instantiate_signature(proto_ctor.py_signature,
 ? File
"/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/instantiations.py",
line 368, in _instantiate_signature
 ??? i_arg = _instantiate_argument(proto_arg, proto_class, tmpl_names,  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/instantiations.py",
line 191, in _instantiate_argument
 ??? i_arg.default_value = [_instantiate_value(v, expansions)  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/instantiations.py",
line 191, in <listcomp>
 ??? i_arg.default_value = [_instantiate_value(v, expansions)  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/instantiations.py",
line 437, in _instantiate_value
 ??? i_name = ScopedName.parse(template_string(proto_name, expansions))  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/templates.py",
line 201, in template_string
 ??? proto_str = proto_str.replace(name, value)
AttributeError: 'ScopedName' object has no attribute 'replace'
make[2]: ***
[python/CMakeFiles/python_module_qgis__analysis.dir/build.make:853: 
python/analysis/build/_analysis/sip_analysispart0.cpp] Error 1
make[1]: *** [CMakeFiles/Makefile2:5790: 
python/CMakeFiles/python_module_qgis__analysis.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....


sip-build: An internal error occurred...
Traceback (most recent call last):
 ? File "/bin/sip-build", line 33, in <module>  ??? sys.exit(load_entry_point('sip==6.6.2', 'console_scripts',
'sip-build')())
 ? File "/usr/lib64/python3.10/site-packages/sipbuild/tools/build.py",
line 37, in main
 ??? handle_exception(e)
 ? File "/usr/lib64/python3.10/site-packages/sipbuild/exceptions.py",
line 81, in handle_exception
 ??? raise e
 ? File "/usr/lib64/python3.10/site-packages/sipbuild/tools/build.py",
line 34, in main
 ??? project.build()
 ? File "/usr/lib64/python3.10/site-packages/sipbuild/project.py", line 244, in build  ??? self.builder.build()  ? File "/usr/lib64/python3.10/site-packages/sipbuild/builder.py", line 48, in build  ??? self._generate_bindings()  ? File "/usr/lib64/python3.10/site-packages/sipbuild/builder.py", line 277, in _generate_bindings  ??? buildable = bindings.generate()  ? File "/usr/lib64/python3.10/site-packages/sipbuild/bindings.py", line 166, in generate  ??? spec, sip_files = parse(self.sip_file, SIP_VERSION, encoding,  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/parser.py",
line 35, in parse
 ??? protected_is_public, include_dirs, strict).parse(sip_file)  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/parser_manager.py",
line 1507, in parse
 ??? self._parser.parse(self._read(sip_file, raw_sip_file),  ? File "/usr/lib/python3.10/site-packages/ply/yacc.py", line 331, in parse  ??? return self.parseopt(input, lexer, debug, tracking, tokenfunc)  ? File "/usr/lib/python3.10/site-packages/ply/yacc.py", line 823, in parseopt  ??? p.callable(pslice)  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/rules.py",
line 3029, in p_typedef_decl
 ??? instantiated = pm.instantiate_class_template(p, name_symbol,  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/parser_manager.py",
line 1480, in instantiate_class_template  ??? instantiate_class(p, symbol, fq_cpp_name, tmpl_names, proto_class,  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/instantiations.py",
line 131, in instantiate_class
 ??? i_class.ctors = _instantiate_ctors(tmpl_names, proto_class, template,  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/instantiations.py",
line 235, in _instantiate_ctors
 ??? i_ctor.py_signature = _instantiate_signature(proto_ctor.py_signature,
 ? File
"/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/instantiations.py",
line 368, in _instantiate_signature
 ??? i_arg = _instantiate_argument(proto_arg, proto_class, tmpl_names,  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/instantiations.py",
line 191, in _instantiate_argument
 ??? i_arg.default_value = [_instantiate_value(v, expansions)  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/instantiations.py",
line 191, in <listcomp>
 ??? i_arg.default_value = [_instantiate_value(v, expansions)  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/instantiations.py",
line 437, in _instantiate_value
 ??? i_name = ScopedName.parse(template_string(proto_name, expansions))  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/templates.py",
line 201, in template_string
 ??? proto_str = proto_str.replace(name, value)
AttributeError: 'ScopedName' object has no attribute 'replace'
make[2]: ***
[python/CMakeFiles/python_module_qgis__core.dir/build.make:804: 
python/core/build/_core/sip_corepart0.cpp] Error 1
make[1]: *** [CMakeFiles/Makefile2:5683: 
python/CMakeFiles/python_module_qgis__core.dir/all] Error 2


sip-build: An internal error occurred...
Traceback (most recent call last):
 ? File "/bin/sip-build", line 33, in <module>  ??? sys.exit(load_entry_point('sip==6.6.2', 'console_scripts',
'sip-build')())
 ? File "/usr/lib64/python3.10/site-packages/sipbuild/tools/build.py",
line 37, in main
 ??? handle_exception(e)
 ? File "/usr/lib64/python3.10/site-packages/sipbuild/exceptions.py",
line 81, in handle_exception
 ??? raise e
 ? File "/usr/lib64/python3.10/site-packages/sipbuild/tools/build.py",
line 34, in main
 ??? project.build()
 ? File "/usr/lib64/python3.10/site-packages/sipbuild/project.py", line 244, in build  ??? self.builder.build()  ? File "/usr/lib64/python3.10/site-packages/sipbuild/builder.py", line 48, in build  ??? self._generate_bindings()  ? File "/usr/lib64/python3.10/site-packages/sipbuild/builder.py", line 277, in _generate_bindings  ??? buildable = bindings.generate()  ? File "/usr/lib64/python3.10/site-packages/sipbuild/bindings.py", line 166, in generate  ??? spec, sip_files = parse(self.sip_file, SIP_VERSION, encoding,  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/parser.py",
line 35, in parse
 ??? protected_is_public, include_dirs, strict).parse(sip_file)  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/parser_manager.py",
line 1507, in parse
 ??? self._parser.parse(self._read(sip_file, raw_sip_file),  ? File "/usr/lib/python3.10/site-packages/ply/yacc.py", line 331, in parse  ??? return self.parseopt(input, lexer, debug, tracking, tokenfunc)  ? File "/usr/lib/python3.10/site-packages/ply/yacc.py", line 823, in parseopt  ??? p.callable(pslice)  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/rules.py",
line 3029, in p_typedef_decl
 ??? instantiated = pm.instantiate_class_template(p, name_symbol,  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/parser_manager.py",
line 1480, in instantiate_class_template  ??? instantiate_class(p, symbol, fq_cpp_name, tmpl_names, proto_class,  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/instantiations.py",
line 131, in instantiate_class
 ??? i_class.ctors = _instantiate_ctors(tmpl_names, proto_class, template,  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/instantiations.py",
line 235, in _instantiate_ctors
 ??? i_ctor.py_signature = _instantiate_signature(proto_ctor.py_signature,
 ? File
"/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/instantiations.py",
line 368, in _instantiate_signature
 ??? i_arg = _instantiate_argument(proto_arg, proto_class, tmpl_names,  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/instantiations.py",
line 191, in _instantiate_argument
 ??? i_arg.default_value = [_instantiate_value(v, expansions)  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/instantiations.py",
line 191, in <listcomp>
 ??? i_arg.default_value = [_instantiate_value(v, expansions)  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/parser/instantiations.py",
line 437, in _instantiate_value
 ??? i_name = ScopedName.parse(template_string(proto_name, expansions))  ? File "/usr/lib64/python3.10/site-packages/sipbuild/generator/templates.py",
line 201, in template_string
 ??? proto_str = proto_str.replace(name, value)
AttributeError: 'ScopedName' object has no attribute 'replace'
make[2]: ***
[python/CMakeFiles/python_module_qgis__gui.dir/build.make:1253: 
python/gui/build/_gui/sip_guipart0.cpp] Error 1
make[1]: *** [CMakeFiles/Makefile2:5737: 
python/CMakeFiles/python_module_qgis__gui.dir/all] Error 2
make: *** [Makefile:156: all] Error 2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20220628/43e5e8ef/attachment.htm>

------------------------------

Subject: Digest Footer

_______________________________________________
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


------------------------------

End of QGIS-Developer Digest, Vol 200, Issue 33
***********************************************


More information about the QGIS-Developer mailing list