Hi all,<br><br>I&#39;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&#39;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[&#39;GISBASE&#39;] = r&quot; ....path to QGIS ....<br>sys.path.append(os.path.join(os.environ[&#39;GISBASE&#39;], &quot;etc&quot;, &quot;python&quot;))&quot;<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">
&gt;&gt;&gt; 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 &quot;&lt;input&gt;&quot;, line 1, in &lt;module&gt;</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 &quot;C:/PROGRA~1/QUANTU~2/apps/qgis/./python\qgis\utils.py&quot;, 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 &quot;C:\Program Files\Quantum GIS Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\__init__.py&quot;, line 1, in &lt;module&gt;</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 &quot;C:/PROGRA~1/QUANTU~2/apps/qgis/./python\qgis\utils.py&quot;, 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 &quot;C:\Program Files\Quantum GIS Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\core.py&quot;, line 1073, in &lt;module&gt;</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(&#39;DEBUG&#39;, 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 &quot;C:\Program Files\Quantum GIS Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\core.py&quot;, 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(&quot;g.gisenv&quot;, flags=&#39;n&#39;)</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 &quot;C:\Program Files\Quantum GIS Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\core.py&quot;, 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 &quot;C:\Program Files\Quantum GIS Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\core.py&quot;, 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 &quot;C:\Program Files\Quantum GIS Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\core.py&quot;, 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 &quot;C:\Program Files\Quantum GIS Wroclaw\apps\grass\grass-6.4.1\etc\python\grass\script\core.py&quot;, 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 &quot;C:\PROGRA~1\QUANTU~2\apps\Python25\lib\subprocess.py&quot;, 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 &quot;C:\PROGRA~1\QUANTU~2\apps\Python25\lib\subprocess.py&quot;, 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 &quot;C:\PROGRA~1\QUANTU~2\apps\Python25\lib\subprocess.py&quot;, 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&#39;m not able to resolve this issue. I haven&#39;t test yet, but I&#39;m pretty sure it&#39;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>