0

I can't import Grass in Console of Qgis (1.9.0 Master). I am guessing it is because of some Grass environment variables which are not set up correctly. However I don't understand why it is working when I start my script directly from the script editor (new feature in QGIS 1.9 it seems). How come environment variables could be set up differently for the console and for the editor?

Thanks in advance for any explanation and help with this. I would like my script start from the console (with command execfile)

import grass.script as grass

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:/Program Files (x86)/QGIS Weekly/apps/qgis-dev/./python\qgis\utils.py", line 453, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
ImportError: No module named script
2
  • This part of the path looks "unhealthy"...: qgis-dev/./python\qgis
    – markusN
    Commented Jul 8, 2013 at 23:31
  • How come environment variables could be set up differently for the console and for the editor? this is a bug because the editor runs a Python as a subprocess which is going to change.
    – Nathan W
    Commented Jul 8, 2013 at 23:54

1 Answer 1

1

What is happening here is when you do import grass is it is picking up the grass package that belongs to Sextante. Which doesn't have a script package. How do we know? Like this:

>>> import grass
>>> help(grass)

Help on package grass:

NAME
    grass

FILE
    c:\osgeo4w\apps\qgis-dev\python\plugins\sextante\grass\__init__.py

A fix now is to add a __init__.py file to the C:\OSGeo4W\apps\grass\grass-6.4.3RC3\etc\python folder so we can import that via a different name:

import python.grass.script

However the correct fix would be to rename the grass folder in sextante so it doesn't conflict. Should be easy for the Sextente author.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.