Установил OSGeo4W64 в C:\OSGeo4W64
Установил дополнительно Python в C"\Python27
GRASS - версии 7.0.4.
Написал тестовый скрипт D:\my_grass.py, который создает временный location (в конце скрипта он удаляется), инициализирует grass.script, и пытается сделать самую простую команду - выдачу сообщения gscript.message('--- GRASS GIS 7 ----')
До этого места - все работает. Но при попытке выполнить gscript.message - появляется сообщение об ошибке.
Вот сам скрипт:
Код: Выделить всё
import os
import sys
import subprocess
import shutil
import binascii
import tempfile
OSGeo4W64Dir = r'C:\OSGeo4W64'
grassVersionDir = 'grass-7.0.4'
grassBatFileName = 'grass70.bat'
grassBatFile = os.path.join( OSGeo4W64Dir, 'bin', grassBatFileName )
GISBASEPath = os.environ['GISBASE'] = os.path.join(OSGeo4W64Dir, 'apps', 'grass', grassVersionDir)
LD_LIBRARY_PATH = os.environ['LD_LIBRARY_PATH'] = os.path.join(GISBASEPath, 'lib')
PYTHONLIB = os.environ['PYTHONLIB'] = r'C:\Python27'
PYTHONPATH = os.environ['PYTHONPATH'] = os.path.join(GISBASEPath, 'etc', 'python')
sys.path.append(PYTHONPATH) # !!!!
GRASS_SH = os.environ['GRASS_SH'] = os.path.join(OSGeo4W64Dir, 'apps', 'msys', 'bin', 'sh.exe')
###############
GISBASEBinPath = os.path.join(GISBASEPath, 'bin')
GISBASEBinScripts = os.path.join(GISBASEPath, 'scripts')
sys.path.append(GISBASEPath)
sys.path.append(GISBASEBinPath)
sys.path.append(PYTHONLIB)
sys.path.append(LD_LIBRARY_PATH)
sys.path.append(GISBASEBinScripts)
os.environ['PATH'] += GISBASEPath
os.environ['PATH'] += GISBASEBinPath
os.environ['PATH'] += PYTHONPATH
os.environ['PATH'] += PYTHONLIB
os.environ['PATH'] += LD_LIBRARY_PATH
os.environ['PATH'] += GISBASEBinScripts
###############
gisdb = os.path.join(tempfile.gettempdir(), 'grassdata')
os.environ['GISDBASE'] = gisdb
try:
os.stat(gisdb)
except:
os.mkdir(gisdb)
string_length = 16
location = binascii.hexlify(os.urandom(string_length))
mapset = 'PERMANENT'
location_path = os.path.join(gisdb, location)
myepsg = '3044'
startcmd = grassBatFile + ' -c epsg:' + myepsg + ' -e ' + location_path
print startcmd
p = subprocess.Popen(startcmd, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
if p.returncode != 0:
print >> sys.stderr, 'ERROR: %s' % err
print >> sys.stderr, 'ERROR: Cannot generate location (%s)' % startcmd
sys.exit(-1)
else:
print 'Created location %s' % location_path
import grass.script as gscript
import grass.script.setup as gsetup
gsetup.init(GISBASEPath, gisdb, location, mapset)
gscript.message('--- GRASS GIS 7 ----')
shutil.rmtree(location_path)
sys.exit(0)
Код: Выделить всё
C:\OSGeo4W64\bin\grass70.bat -c epsg:3044 -e c:\users\vadimk\appdata\local\temp\grassdata\7f9cb7c41498f1dab61358624241de85
Created location c:\users\vadimk\appdata\local\temp\grassdata\7f9cb7c41498f1dab61358624241de85
Traceback (most recent call last):
File "D:\my_grass.py", line 110, in <module>
gscript.message('--- GRASS GIS 7: Current GRASS GIS 7 environment:')
File "C:\OSGeo4W64\apps\grass\grass-7.0.4\etc\python\grass\script\core.py", line 548, in message
run_command("g.message", flags=flag, message=msg, errors='ignore')
File "C:\OSGeo4W64\apps\grass\grass-7.0.4\etc\python\grass\script\core.py", line 393, in run_command
ps = start_command(*args, **kwargs)
File "C:\OSGeo4W64\apps\grass\grass-7.0.4\etc\python\grass\script\core.py", line 356, in start_command
if debug_level() > 0:
File "C:\OSGeo4W64\apps\grass\grass-7.0.4\etc\python\grass\script\core.py", line 1519, in debug_level
_debug_level = int(gisenv().get('DEBUG', 0))
File "C:\OSGeo4W64\apps\grass\grass-7.0.4\etc\python\grass\script\core.py", line 935, in gisenv
s = read_command("g.gisenv", flags='n')
File "C:\OSGeo4W64\apps\grass\grass-7.0.4\etc\python\grass\script\core.py", line 446, in read_command
return handle_errors(returncode, stdout, args, kwargs)
File "C:\OSGeo4W64\apps\grass\grass-7.0.4\etc\python\grass\script\core.py", line 313, in handle_errors
returncode=returncode)
CalledModuleError: Module run None ['g.gisenv', '-n'] ended with error
Process ended with non-zero return code -1073741701. See errors in the (error) output.
Код: Выделить всё
print gscript.gisenv()
in_region = gscript.region()
и т.д.
Подскажите, в чем может быть проблема?