[Pywps-dev] Import qgis.core into PyWPS process

Jáchym Čepický jachym.cepicky at gmail.com
Mon Jan 2 12:56:19 PST 2017


Well,

I have no idea, how you confiured the PYTHONPATH

but try (already proposed)

import sys
sys.path.append("/path/to/qgis/")

J

Dne 2.1.2017 v 21:54 Eduardo Silverio da Silva napsal(a):
> I have checked the GetCapabilities by accessing:
> http://localhost:8080/cgi-bin/pywps.cgi?service=wps&request=GetCapabilities&version=1.0.0
> and it is okay. I can even execute the example process "inputs_added".
>
> Then a have checked the log messages and the result is:
>
> PyWPS [2017-01-02 18:49:34,355] INFO: Setting PYWPS_PROCESSES from
> configuration file to c:/pywps/pywps_processes
> PyWPS [2017-01-02 18:49:34,388] WARNING: Could not import processes from
> 'pywps_processes': ImportError('No module named qgis.core',)
> PyWPS [2017-01-02 18:49:34,424] INFO: Following processes are imported:
> ['inputs_added']
> Traceback (most recent call last):
>   File "C:/pywps\pywps\Wps\__init__.py", line 174, in _init_from_directory
>     [processSources.__name__])
>   File "c:/pywps/pywps_processes\processing.py", line 2, in <module>
>     from qgis.core import *
> ImportError: No module named qgis.core
>
> As we can see, the only process imported was the "input_added", while my
> other algorithm "processing" gave an ImportError.
>
> Eduardo,
>
> 2017-01-02 18:42 GMT-02:00 Jáchym Čepický <jachym.cepicky at gmail.com>:
>
>> Hi,
>>
>> first check, if your GetCapabilities response is ok (
>> http://server/wps?service=wps&request=getcapabilities) - maybe the plugin
>> is corrupted (it's not the stablest piece of software).
>>
>> Then please one more time: check the error.log of your web server, there
>> should be written more - you can pass any exception or error message either
>> to the mailing list or share it via pastebin.net or similar service
>>
>> J
>>
>> Dne 2.1.2017 v 21:38 Eduardo Silverio da Silva napsal(a):
>>
>>> In my case I am using QGIS 2.18 (x32) and Python 2.7.13 (x32) on Windows
>>> 10, and I have already added the following environment variables:
>>>
>>> PYTHONPATH:
>>> C:\Program Files (x86)\QGIS 2.18\apps\qgis\python
>>> C:\Program Files (x86)\QGIS 2.18\apps\qgis\python\plugins
>>> C:\Program Files (x86)\QGIS 2.18\apps\Python27\Lib\site-packages
>>>
>>> PATH:
>>> C:\Program Files (x86)\QGIS 2.18\bin
>>> C:\Program Files (x86)\QGIS 2.18\apps\qgis\bin
>>> C:\Python27
>>> C:\Python27\Scripts
>>>
>>> Here is the code where I want to import the classes:
>>>
>>> #I would like to use these classes:
>>> # from qgis.core import *
>>> # from qgis.gui import *
>>> # from processing.core.Processing import Processing
>>> # import processing
>>>
>>> from pywps.Process import WPSProcess
>>> from types import FloatType
>>>
>>> class Process(WPSProcess):
>>>      def __init__(self):
>>>          WPSProcess.__init__(self,
>>>               identifier       = "processar",
>>>               title            = "Title",
>>>               version          = "1",
>>>               storeSupported   = "false",
>>>               statusSupported  = "false",
>>>               abstract         = "Abstract")
>>>
>>>          self.value1 = self.addLiteralInput(identifier = "value1", title
>>> =
>>> "Input 1", type = FloatType)
>>>          self.value2 = self.addLiteralInput(identifier = "value2", title
>>> =
>>> "Input 2", type = FloatType)
>>>          self.result = self.addLiteralOutput(identifier = "result",
>>> title =
>>> "Result", type = FloatType)
>>>
>>>      def execute(self):
>>>     # Here I would like to write the necessary code to execute the
>>> qgis:extractnodes algorithm:
>>>     # processing.runalg('qgis:extractnodes', 'river.shp', 'output.shp')
>>>
>>> v1 = self.value1.getValue()
>>>          v2 = self.value2.getValue()
>>>          self.result.setValue(v1 + v2)
>>>          return
>>> --------------------------------------
>>>
>>> But even with those PATH variables configured I could not access the
>>> algorithm via WPS-client plugin.
>>>
>>> Regards,
>>>
>>>
>>> 2017-01-02 17:31 GMT-02:00 Salvatore Larosa <lrssvtml at gmail.com>:
>>>
>>> Hi,
>>>>
>>>> On Mon, Jan 2, 2017 at 4:31 PM, Eduardo Silverio da Silva <
>>>> eduardosilverio1990 at gmail.com> wrote:
>>>>
>>>> Hello people,
>>>>>
>>>>> I have a python script that uses some classes from qgis and it runs
>>>>> correctly in my standalone app (IDLE Python). But when I try to publish
>>>>> the
>>>>> script through PyWPS (3.2.5), the process does not apear in the list of
>>>>> GetCapabilities. I think the problem is with the following imports:
>>>>>
>>>>> from qgis.core import *
>>>>> from qgis.gui import *
>>>>> from processing.core.Processing import Processing
>>>>>
>>>>> When I comment these lines the algorithm is showed.
>>>>>
>>>>>
>>>> I guess the problem is with your environment variable, you should add the
>>>> QGIS python and plugins paths to PYTHONPATH and probably the QGIS lib
>>>> path
>>>> to LD_LIBRARY.
>>>>
>>>> Also, any error message could be useful in order to get some help from
>>>> the
>>>> community. :)
>>>>
>>>> Regards,
>>>> -SL
>>>>
>>>>
>>>> --
>>>> Salvatore Larosa
>>>> linkedIn: http://linkedin.com/in/larosasalvatore
>>>> twitter: @lrssvt
>>>> skype: s.larosa
>>>> IRC: lrssvt on freenode
>>>>
>>>>
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> pywps-dev mailing list
>>> pywps-dev at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/pywps-dev
>>>
>>>
>> --
>> Jachym Cepicky
>> e-mail: jachym.cepicky at gmail.com
>> twitter: @jachymc
>>
>
>
>

-- 
Jachym Cepicky
e-mail: jachym.cepicky at gmail.com
twitter: @jachymc


More information about the pywps-dev mailing list