[GRASS-user] can't get model to run in python

gisrs gisrs at live.co.uk
Tue Jul 5 10:00:01 EDT 2011


Hi i'm having some problems getting a model i've built in the graphical
modeller to work as a python script once i've exported it. i keep getting
the error 

Traceback (most recent call last):
File "I:\Brighton_Flow_Routing\Model.py", line 19, in <module>
import grass.script as grass
ImportError: No module named grass.script

i've done a bit of searching and saw some forum post mentioning the need to
have additional lines added to the script telling it where the python
elements were located so i added the following under "import Sys"

sys.path.append('D:\\Program Files x86\\Grass 6.4\\GRASS 6.4.1\\etc') 
sys.path.append('D:\\Program Files x86\\Grass 6.4\\GRASS
6.4.1\\etc\\python') 
sys.path.append('D:\\Program Files x86\\Grass 6.4\\GRASS 6.4.1\\lib') 
sys.path.append('D:\\Program Files x86\\Grass 6.4\\GRASS 6.4.1') 
sys.path.append('D:\\Program Files x86\\Grass 6.4\\GRASS 6.4.1\\extralib') 
sys.path.append('D:\\Program Files x86\\Grass 6.4\\GRASS 6.4.1\\msys\\bin') 

but still no luck getting it to run i get the following error 

Traceback (most recent call last):
  File "I:\Brighton_Flow_Routing\model.py", line 25, in <module>
    import grass.script as grass
  File "D:\Program Files x86\Grass 6.4\GRASS
6.4.1\etc\python\grass\script\__init__.py", line 1, in <module>
    from core   import *
  File "D:\Program Files x86\Grass 6.4\GRASS
6.4.1\etc\python\grass\script\core.py", line 37, in <module>
    gettext.install('grasslibs', os.path.join(os.getenv("GISBASE"),
'locale'), unicode=True)
  File "C:\Python27\lib\ntpath.py", line 96, in join
    assert len(path) > 0
TypeError: object of type 'NoneType' has no len()
>>> 

using python 2.7.2, grass 6.4.1 & windows 7 64 bit

please does anyone know how i fix this?

see below for the complete script 

import sys
sys.path.append('D:\\Program Files x86\\Grass 6.4\\GRASS 6.4.1\\etc') 
sys.path.append('D:\\Program Files x86\\Grass 6.4\\GRASS
6.4.1\\etc\\python') 
sys.path.append('D:\\Program Files x86\\Grass 6.4\\GRASS 6.4.1\\lib') 
sys.path.append('D:\\Program Files x86\\Grass 6.4\\GRASS 6.4.1') 
sys.path.append('D:\\Program Files x86\\Grass 6.4\\GRASS 6.4.1\\extralib') 
sys.path.append('D:\\Program Files x86\\Grass 6.4\\GRASS 6.4.1\\msys\\bin') 
import os
import atexit

import grass.script as grass

def cleanup():
    pass

def main():
    grass.run_command("v.in.ogr",
                      dsn =
"I:\Brighton_Flow_Routing\Node_Split\Node_1.TAB",
                      output = "N_1")
    grass.run_command("r.drain",
                      input = "DTM_1m_Filled",
                      output = "FP_1",
                      vector_points = "N_1")
    grass.run_command("r.thin",
                      input = "FP_1",
                      output = "FP_1_T")
    grass.run_command("r.to.vect",
                      input = "FP_1_T",
                      output = "FP_1_T_V",
                      feature = "line")
    grass.run_command("v.out.ogr",
                      input = "FP_1_T_V",
                      type = "line",
                      dsn =
"\\data\Projects\Brighton_Flow_Routing\Flow_Routes",
                      format = "MapInfo_File")

    return 0

if __name__ == "__main__":
    options, flags = grass.parser()
    atexit.register(cleanup)
    sys.exit(main())


--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/can-t-get-model-to-run-in-python-tp6549853p6549853.html
Sent from the Grass - Users mailing list archive at Nabble.com.


More information about the grass-user mailing list