[GRASS-user] Grass 6.4 & python.

Hi Grass-gurus,

I know that the grass 7 will works with python.
But can I play with grass 6.4 (under Msys) and python?
Case yes, could you send me some tips how
can I do this?
By the way, running under Windows Vista and/or
Linux Ubuntu.

Thanks a lot

milton ribeiro
brazil-toronto

I know that the grass 7 will works with python.
But can I play with grass 6.4 (under Msys) and python?

Yes!!

you can see about that in http://grass.osgeo.org/grass64/manuals/html64_user/wxGUI.html

Case yes, could you send me some tips how

can I do this?

just type in your terminal grass64 -wxpython

By the way, running under Windows Vista and/or
Linux Ubuntu.

Thanks a lot

milton ribeiro
brazil-toronto


Ahora lee tus emails de Hotmail desde tu móvil Vodafone ¡Aquí!

Thanks Jhon,

I started grass under Msys and with the flag -wx.
My difficult now I how can I get starting, with a simple example, like
these on the grass-python page:

import sys
import grass
def main():
drape_map = options[‘drapemap’]
relief_map = options[‘reliefmap’]
brighten = options[‘brighten’]
ret = grass.run_command(“d.his”, h_map = drapemap, i_map = relief_map, brighten = brighten)
sys.exit(ret)
if name == “main”:
options, flags = grass.parser()
main()

My question is how can I make python find the “grass” to run the import.
I need to start python inside a MSYS → GRASS session, like R do?

Regards

milton

2009/4/28 Jhon Ortiz <eljhonjhon@hotmail.com>

I know that the grass 7 will works with python.
But can I play with grass 6.4 (under Msys) and python?

Yes!!

you can see about that in http://grass.osgeo.org/grass64/manuals/html64_user/wxGUI.html

Case yes, could you send me some tips how

can I do this?

just type in your terminal grass64 -wxpython

By the way, running under Windows Vista and/or

Linux Ubuntu.

Thanks a lot

milton ribeiro
brazil-toronto


Ahora lee tus emails de Hotmail desde tu móvil Vodafone ¡Aquí!

Milton Cezar Ribeiro wrote:

I started grass under Msys and with the flag -wx.
My difficult now I how can I get starting, with a simple example, like
these on the grass-python page:

My question is how can I make python find the "grass" to run the import.
I need to start python inside a MSYS -> GRASS session, like R do?

In order to find grass.py, PYTHONPATH needs to include
$GISBASE/etc/python. This is done automatically when you start GRASS.

However, the functions in grass.py run GRASS commands, and so require
the usual GRASS environment (GISBASE, GISRC, etc). So you need to
either run the Python script from within a GRASS session, or set up
the GRASS environment by some other means.

If you want to write a stand-alone program, you could always have the
Python script set up the GRASS environment, e.g. from registry keys
(or if this is for your own use, just hard-code everything). You can
add directories to the path used for importing Python modules by
modifying sys.path, e.g.:

  import sys
  ...
  gisbase = os.normpath(os.environ['GISBASE'])
  pydir = os.path.join(gisbase, "etc", "python")
  sys.path.append(pydir)

You still need to figure out how to determine the database, location,
and mapset, though.

--
Glynn Clements <glynn@gclements.plus.com>

Hi Glym,

Thanks for the reply. I have tryed on two ways, both not work for me (under windows vista).

  1. start msys; start grass without -mx ; and try to start python from inside grass sesssion. The python keep stoped (no error message, but stay with only “python” words on the console)

  2. start msys; try to start grass -mx
    here I get the following error:
    GRASS 6.4.0RC4 > grass65 -wx
    Cleaning up temporary files …
    Starting GRASS …
    ‘import site’ failed; use -v for traceback
    Traceback (most recent call last):
    File “c:/OSGeo4W/apps/grass/grass-6.5.svn/etc/wxpython/gis_set.py”, line 23, in
    import os
    ImportError: No module named os
    Error in GUI startup. If necessary, please
    report this error to the GRASS developers.
    Switching to text mode now.
    Hit RETURN to continue…

Any help are welcome.

Bests

milton

2009/4/29 Glynn Clements <glynn@gclements.plus.com>

Milton Cezar Ribeiro wrote:

I started grass under Msys and with the flag -wx.
My difficult now I how can I get starting, with a simple example, like
these on the grass-python page:

My question is how can I make python find the “grass” to run the import.
I need to start python inside a MSYS → GRASS session, like R do?

In order to find grass.py, PYTHONPATH needs to include
$GISBASE/etc/python. This is done automatically when you start GRASS.

However, the functions in grass.py run GRASS commands, and so require
the usual GRASS environment (GISBASE, GISRC, etc). So you need to
either run the Python script from within a GRASS session, or set up
the GRASS environment by some other means.

If you want to write a stand-alone program, you could always have the
Python script set up the GRASS environment, e.g. from registry keys
(or if this is for your own use, just hard-code everything). You can
add directories to the path used for importing Python modules by
modifying sys.path, e.g.:

import sys

gisbase = os.normpath(os.environ[‘GISBASE’])
pydir = os.path.join(gisbase, “etc”, “python”)
sys.path.append(pydir)

You still need to figure out how to determine the database, location,
and mapset, though.


Glynn Clements <glynn@gclements.plus.com>

oops I typed “grass -mx” on email instead of “grass -wx”. Sorry.

2009/4/29 Milton Cezar Ribeiro <miltinho.astronauta@gmail.com>

Hi Glym,

Thanks for the reply. I have tryed on two ways, both not work for me (under windows vista).

  1. start msys; start grass without -mx ; and try to start python from inside grass sesssion. The python keep stoped (no error message, but stay with only “python” words on the console)

  2. start msys; try to start grass -mx
    here I get the following error:
    GRASS 6.4.0RC4 > grass65 -wx
    Cleaning up temporary files …
    Starting GRASS …
    ‘import site’ failed; use -v for traceback
    Traceback (most recent call last):
    File “c:/OSGeo4W/apps/grass/grass-6.5.svn/etc/wxpython/gis_set.py”, line 23, in
    import os
    ImportError: No module named os
    Error in GUI startup. If necessary, please
    report this error to the GRASS developers.
    Switching to text mode now.
    Hit RETURN to continue…

Any help are welcome.

Bests

milton

2009/4/29 Glynn Clements <glynn@gclements.plus.com>

Milton Cezar Ribeiro wrote:

I started grass under Msys and with the flag -wx.
My difficult now I how can I get starting, with a simple example, like
these on the grass-python page:

My question is how can I make python find the “grass” to run the import.
I need to start python inside a MSYS → GRASS session, like R do?

In order to find grass.py, PYTHONPATH needs to include
$GISBASE/etc/python. This is done automatically when you start GRASS.

However, the functions in grass.py run GRASS commands, and so require
the usual GRASS environment (GISBASE, GISRC, etc). So you need to
either run the Python script from within a GRASS session, or set up
the GRASS environment by some other means.

If you want to write a stand-alone program, you could always have the
Python script set up the GRASS environment, e.g. from registry keys
(or if this is for your own use, just hard-code everything). You can
add directories to the path used for importing Python modules by
modifying sys.path, e.g.:

import sys

gisbase = os.normpath(os.environ[‘GISBASE’])
pydir = os.path.join(gisbase, “etc”, “python”)
sys.path.append(pydir)

You still need to figure out how to determine the database, location,
and mapset, though.


Glynn Clements <glynn@gclements.plus.com>

Milton Cezar Ribeiro wrote:

Thanks for the reply. I have tryed on two ways, both not work for me (under
windows vista).

'import site' failed; use -v for traceback Traceback (most recent call last):
  File "c:/OSGeo4W/apps/grass/grass-6.5.svn/etc/wxpython/gis_set.py", line
23, in <module>
    import os
ImportError: No module named os

This indicates that your Python installation is borked; it can't find
its standard library modules.

--
Glynn Clements <glynn@gclements.plus.com>

Hi Glym,

But if you go to a DOS windows (using cmd)
type python (it starts python 2.6)
and try import sys, it works fine on text/DOS mode?
By the way, the pythopath was included as windows environment variable.

Any suggestion?

miltinho

2009/4/29 Glynn Clements <glynn@gclements.plus.com>

Milton Cezar Ribeiro wrote:

Thanks for the reply. I have tryed on two ways, both not work for me (under
windows vista).

‘import site’ failed; use -v for traceback Traceback (most recent call last):
File “c:/OSGeo4W/apps/grass/grass-6.5.svn/etc/wxpython/gis_set.py”, line
23, in
import os
ImportError: No module named os

This indicates that your Python installation is borked; it can’t find
its standard library modules.

Glynn Clements <glynn@gclements.plus.com>

oops again:

" But if I go to a DOS windows (using cmd)"

2009/4/29 Milton Cezar Ribeiro <miltinho.astronauta@gmail.com>

Hi Glym,

But if you go to a DOS windows (using cmd)
type python (it starts python 2.6)
and try import sys, it works fine on text/DOS mode?
By the way, the pythopath was included as windows environment variable.

Any suggestion?

miltinho

2009/4/29 Glynn Clements <glynn@gclements.plus.com>

Milton Cezar Ribeiro wrote:

Thanks for the reply. I have tryed on two ways, both not work for me (under
windows vista).

‘import site’ failed; use -v for traceback Traceback (most recent call last):
File “c:/OSGeo4W/apps/grass/grass-6.5.svn/etc/wxpython/gis_set.py”, line
23, in
import os
ImportError: No module named os

This indicates that your Python installation is borked; it can’t find
its standard library modules.

Glynn Clements <glynn@gclements.plus.com>

Hi Milton,
This is a common error I have come across, and shouldn't be a problem
with your Python installation. It is just a question of getting
PYTHONPATH and possibly PYTHONHOME (Which needs to be in a windows
path format) into the right format.

For example, the following has been added to the native wingrass
installer's version of the "grass64" startup script. Make sure to
adjust the paths to your computer's locations.

# Set the PYTHONPATH variable
PYTHONPATH="$GISBASE/etc/python:$GISBASE/Python25:$PYTHONPATH"
export PYTHONPATH
PYTHONHOME="C:\GRASS-6-SVN\Python25"
export PYTHONHOME

Also, check http://trac.osgeo.org/grass/wiki/CompileOnWindows#Usage
for details on how to get Python running under msys on windows.

Note: even with these adjustments, wxpython still can't display maps
on grass-6.5.svn or grass-7.0.svn

-Colin

On Wed, Apr 29, 2009 at 11:44 AM, Milton Cezar Ribeiro
<miltinho.astronauta@gmail.com> wrote:

oops again:

" But if I go to a DOS windows (using cmd)"

2009/4/29 Milton Cezar Ribeiro <miltinho.astronauta@gmail.com>

Hi Glym,

But if you go to a DOS windows (using cmd)
type python (it starts python 2.6)
and try import sys, it works fine on text/DOS mode?
By the way, the pythopath was included as windows environment variable.

Any suggestion?
miltinho
2009/4/29 Glynn Clements <glynn@gclements.plus.com>

Milton Cezar Ribeiro wrote:

> Thanks for the reply. I have tryed on two ways, both not work for me
> (under
> windows vista).

> 'import site' failed; use -v for traceback Traceback (most recent call
> last):
> File "c:/OSGeo4W/apps/grass/grass-6.5.svn/etc/wxpython/gis_set.py",
> line
> 23, in <module>
> import os
> ImportError: No module named os

This indicates that your Python installation is borked; it can't find
its standard library modules.

--
Glynn Clements <glynn@gclements.plus.com>

_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

Hi Colin

I will give a look on all these tips.

Thanks a lot.

milton

2009/4/29 Colin Nielsen <colin.nielsen@gmail.com>

Hi Milton,
This is a common error I have come across, and shouldn’t be a problem
with your Python installation. It is just a question of getting
PYTHONPATH and possibly PYTHONHOME (Which needs to be in a windows
path format) into the right format.

For example, the following has been added to the native wingrass
installer’s version of the “grass64” startup script. Make sure to
adjust the paths to your computer’s locations.

Set the PYTHONPATH variable

PYTHONPATH=“$GISBASE/etc/python:$GISBASE/Python25:$PYTHONPATH”
export PYTHONPATH
PYTHONHOME=“C:\GRASS-6-SVN\Python25”
export PYTHONHOME

Also, check http://trac.osgeo.org/grass/wiki/CompileOnWindows#Usage
for details on how to get Python running under msys on windows.

Note: even with these adjustments, wxpython still can’t display maps
on grass-6.5.svn or grass-7.0.svn

-Colin

On Wed, Apr 29, 2009 at 11:44 AM, Milton Cezar Ribeiro
<miltinho.astronauta@gmail.com> wrote:

oops again:

" But if I go to a DOS windows (using cmd)"

2009/4/29 Milton Cezar Ribeiro <miltinho.astronauta@gmail.com>

Hi Glym,

But if you go to a DOS windows (using cmd)
type python (it starts python 2.6)
and try import sys, it works fine on text/DOS mode?
By the way, the pythopath was included as windows environment variable.

Any suggestion?
miltinho
2009/4/29 Glynn Clements <glynn@gclements.plus.com>

Milton Cezar Ribeiro wrote:

Thanks for the reply. I have tryed on two ways, both not work for me
(under
windows vista).

‘import site’ failed; use -v for traceback Traceback (most recent call
last):
File “c:/OSGeo4W/apps/grass/grass-6.5.svn/etc/wxpython/gis_set.py”,
line
23, in
import os
ImportError: No module named os

This indicates that your Python installation is borked; it can’t find
its standard library modules.


Glynn Clements <glynn@gclements.plus.com>


grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user