I’m trying to access Grass functionality via Python outside the shell in the GUI.
import sys, os
gisbase = os.environ[‘GISBASE’] = r’C:\Program Files (x86)\GRASS GIS 7.0.svn’
gisdbase = r’E:\Sample’
location = ‘duplin_phons’
mapset = ‘PERMANENT’
sys.path.append(os.path.join(os.environ[‘GISBASE’], “etc”, “python”, “grass”, “script”))
import grass.script as grass
import grass.script.setup as gsetup
However when I try to run any grass commands I get
ImportError: No module named grass.script
When I’m in the shell and run
import grass.script as grass
print grass.file
I’m returned:
C:\Program Files (x86)\GRASS GIS 7.0.svn\etc\python\grass\script_init_.py
Am I missing a connection somewhere?
Thanks for suggestions
Chad
On Fri, Jul 25, 2014 at 7:29 PM, Chad Ferguson <terrafergus@gmail.com> wrote:
I'm trying to access Grass functionality via Python outside the shell in the
GUI.
Please check this page:
http://grasswiki.osgeo.org/wiki/Working_with_GRASS_without_starting_it_explicitly#Python:_GRASS_GIS_7
It may give you some hints (I have no Windows here to test your code).
Markus
On Fri, Jul 25, 2014 at 1:29 PM, Chad Ferguson <terrafergus@gmail.com>
wrote:
sys.path.append(os.path.join(os.environ['GISBASE'], "etc", "python",
"grass", "script"))
import grass.script as grass
Since the import is `import grass` or similar, you have to add the
directory containing `grass` directory, i.e.:
sys.path.append(os.path.join(os.environ['GISBASE'], "etc", "python"))
By the way, my personal opinion is that
import grass.script as grass
is a bad practice and should be avoided in a new code, the alternative is
not standardized but
import grass.script as gscript
should do.
Vaclav
On 27-Jul-14 3:57 AM, Vaclav Petras wrote:
By the way, my personal opinion is that
import grass.script as grass
is a bad practice and should be avoided in a new code, the alternative is not standardized but
import grass.script as gscript
should do.
What's the reason for that ?
Thanks,
Micha
Vaclav
This mail was received via Mail-SeCure System.
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user
This mail was received via Mail-SeCure System.
--
Moshav Idan
D.N. Arava, 86840
cell: 0523-665918
http://www.surfaces.co.il