Hi all,<br><br>I'm using windows XP and QGIS 1.7 (classic installation, python 2.5, grass 6.4.1 ). My Goal is to create a QGIS plugin for complex network analysis (TSP,steinman tree,...), using GRASS capabilities. It aims to be very user-friendly, and cross-platform.<br>
I'm trying to call GRASS from within a QGIS python plugin, but I get the following error (python console module):<br><br>Code: (inspired by: <a href="http://grass.osgeo.org/wiki/Working_with_GRASS_without_starting_it_explicitly">http://grass.osgeo.org/wiki/Working_with_GRASS_without_starting_it_explicitly</a>)<br>
<blockquote style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;" class="gmail_quote"><blockquote style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;" class="gmail_quote">
import os<br>import sys<br><br>gisbase = os.environ['GISBASE'] = r" ....path to QGIS ....<br>sys.path.append(os.path.join(os.environ['GISBASE'], "etc", "python"))"<br></blockquote>
<div> </div><blockquote style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;" class="gmail_quote">import grass.script as grass<br></blockquote></blockquote><br>Error:<br><blockquote style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;" class="gmail_quote">
>>> import grass.script as grass
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:1;">Traceback (most recent call last):</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:1;"> File "<input>", line 1, in <module></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:1;"> File "C:/PROGRA~1/QUANTU~2/apps/qgis/./python\qgis\utils.py", line 283, in _import</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:1;"> mod = _builtin_import(name, globals, locals, fromlist, level)</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:1;"> File "C:\Program Files\Quantum GIS Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\__init__.py", line 1, in <module></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:1;"> from core import *</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:1;"> File "C:/PROGRA~1/QUANTU~2/apps/qgis/./python\qgis\utils.py", line 283, in _import</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:1;"> mod = _builtin_import(name, globals, locals, fromlist, level)</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:1;"> File "C:\Program Files\Quantum GIS Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\core.py", line 1073, in <module></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:1;"> debug_level = int(gisenv().get('DEBUG', 0))</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:1;"> File "C:\Program Files\Quantum GIS Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\core.py", line 514, in gisenv</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:1;"> s = read_command("g.gisenv", flags='n')</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:1;"> File "C:\Program Files\Quantum GIS Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\core.py", line 225, in read_command</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:1;"> ps = pipe_command(*args, **kwargs)</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:1;"> File "C:\Program Files\Quantum GIS Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\core.py", line 202, in pipe_command</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:1;"> return start_command(*args, **kwargs)</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:1;"> File "C:\Program Files\Quantum GIS Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\core.py", line 164, in start_command</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:1;"> return Popen(args, **popts)</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:1;"> File "C:\Program Files\Quantum GIS Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\core.py", line 55, in __init__</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:1;"> startupinfo, creationflags)</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:1;"> File "C:\PROGRA~1\QUANTU~2\apps\Python25\lib\subprocess.py", line 587, in __init__</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:1;"> errread, errwrite) = self._get_handles(stdin, stdout, stderr)</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:1;"> File "C:\PROGRA~1\QUANTU~2\apps\Python25\lib\subprocess.py", line 700, in _get_handles</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:1;"> p2cread = self._make_inheritable(p2cread)</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:1;"> File "C:\PROGRA~1\QUANTU~2\apps\Python25\lib\subprocess.py", line 745, in _make_inheritable</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:1;"> DUPLICATE_SAME_ACCESS)</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:1;">WindowsError: [Error 6] The handle is invalid</p></blockquote><br><br>I am pretty sure this is due to the Python Path, because the same code works well in a classic python console (outside QGIS). But I'm not able to resolve this issue. I haven't test yet, but I'm pretty sure it's working on ubuntu.<br>
<br>Another Question:<br><br>Does anyone know how to import QGIS vector layer directly into GRASS ( as v.in.ogr.qgis.loc from the GRASS Plugin)<br><br><br>Any help is welcome.<br><br clear="all">Romain,<div><i><br></i></div>
<br>