[GRASS-dev] compiling WINGrass Python Scripts - ExpatError

Hello,

I use the approach as recommended in the wiki to compile
GRASS 6.5 SVN (newest revision 49546) in Windows 7 with msys and the osgeo4w setup etc.
Additionally I want to compile the sourece together with
my own python script. The script itself is very simple and
just for testing (script directory with Makefile is attached).
The script is working as I tested it on my Mac (also compiled
from source). I put the script folder with the description.html
and the Makefile into the script folder and adapted the
Makefile.

It seems that the compilation was successful as there were no
Errors detected and I can start GRASS by calling it via msys.

So far so good, but when I want to call my python script I run
into troubles. I type script.py and get following error:

''''''''''''''''''''''''''''''''''''''''''''
Traceback (most recent call last):
  File "c:\OSGeo4W\apps\grass\grass-6.5.svn\etc\wxpython\gui
_modules\prompt.py", line 1109, in OnKeyPressed

self.parent.RunCmd(cmd)
  File "c:\OSGeo4W\apps\grass\grass-6.5.svn\etc\wxpython\gui
_modules\goutput.py", line 549, in RunCmd

task = gtask.parse_interface(command[0])
  File "c:/osgeo4w/usr/src/grass-6.5.svn/dist.i686-pc-
mingw32/etc/python/grass/script/task.py", line 457, in
parse_interface

tree = etree.fromstring(get_interface_description(name))
  File
"c:\OSGeo4W\apps\Python25\lib\xml\etree\ElementTree.py",
line 964, in XML

return parser.close()
  File
"c:\OSGeo4W\apps\Python25\lib\xml\etree\ElementTree.py",
line 1254, in close

self._parser.Parse("", 1) # end of data
xml.parsers.expat
.
ExpatError
:
no element found: line 1, column 0
''''''''''''''''''''''''''''

I don't know what that exactly means?? I tried to compile the script with two different line endings (UNIX coding and Windows coding) but with similar result. So I don't know what is causing the problem!!

Another thing I realized: I tried to remove the script from the source (the folder and removed the line from the Makefile). I also ran make distclean and removed the configure stamp and then I recompiled GRASS 6.5 without the script. Although I can "call" the script or lets say I get still the same error like before... but if I try to call any weird script (nonexisting.py) I get: 'nonexisting.py' is not recognized as an internal or external command, operable program or batch file.
So it seems that there are remainings of my script although removed from the source an recompiled...strange or not???

Hopefully someone can help,

best regards
Johannes
--
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!
Jetzt informieren: http://www.gmx.net/de/go/freephone

(attachments)

pythontest_l.zip (1.21 KB)

Johannes Radinger wrote:

self._parser.Parse("", 1) # end of data
xml.parsers.expat
.
ExpatError
:
no element found: line 1, column 0
''''''''''''''''''''''''''''

I don't know what that exactly means?? I tried to compile the script
with two different line endings (UNIX coding and Windows coding) but
with similar result. So I don't know what is causing the problem!!

It means that it tried to generate a wxPython GUI for the options, the
code which generates the GUI executed the command with the
--interface-description flag to get a list of the options in XML
format, then passed the output to the Expat XML parser. Unfortunately,
the command failed to execute, so no XML was generated, and Expat
complains about not receiving valid XML.

IOW, the error message is accurate but quite useless. To get useful
information, you'll need to run the script manually from the command
line. Try running it with the --help option initially.

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

Hi,

I tried to run the script now manually with --help
from the command line. For simplicicity I only tried
v.krige.py, a python script that already comes with
the GRASS 6.5 SVN install.

I tried to differnent types but both with problems:

1) with the .py ending:
'''''''''''''''''''''''''''''''''''''''
v.krige.py --help
c:/OSGeo4W/apps/grass/grass-6.5.svn/scripts/v.krige.py:
MODULE: v.krige
AUTHOR(S): Anne Ghisla <a.ghisla AT gmail.com>
PURPOSE: Performs ordinary or block kriging
DEPENDS: R 2.x, packages gstat, maptools and spgrass6,
optional: automap
COPYRIGHT: (C) 2009 by the GRASS Development Team
This program is free software under the GNU General Public
License (>=v2). Read the file COPYING that comes with GRASS
for details.
: command not found
c:/OSGeo4W/apps/grass/grass-6.5.svn/scripts/v.krige.py:
import: command not found
c:/OSGeo4W/apps/grass/grass-6.5.svn/scripts/v.krige.py:
from: command not found
c:/OSGeo4W/apps/grass/grass-6.5.svn/scripts/v.krige.py:
import: command not found
c:/OSGeo4W/apps/grass/grass-6.5.svn/scripts/v.krige.py:
import: command not found
c:/OSGeo4W/apps/grass/grass-6.5.svn/scripts/v.krige.py: line
107: syntax error near unexpected token
`os.environ.has_key("'
c:/OSGeo4W/apps/grass/grass-6.5.svn/scripts/v.krige.py: line
107: `if not os.environ.has_key("GISBASE"):'
(Wed Dec 07 09:29:24 2011) Command finished (0 sec)
Traceback (most recent call last):
   File "c:\OSGeo4W\apps\grass\grass-6.5.svn\etc\wxpython\gui
_modules\goutput.py", line 810, in OnCmdDone

task = menuform.GUI(show = None).ParseCommand(event.cmd)
   File "c:\OSGeo4W\apps\grass\grass-6.5.svn\etc\wxpython\gui
_modules\menuform.py", line 1819, in ParseCommand

blackList = _blackList)
   File "c:/osgeo4w/usr/src/grass-6.5.svn/dist.i686-pc-
mingw32/etc/python/grass/script/task.py", line 457, in
parse_interface
   File
"c:\OSGeo4W\apps\Python25\lib\xml\etree\ElementTree.py",
line 964, in XML

return parser.close()
   File
"c:\OSGeo4W\apps\Python25\lib\xml\etree\ElementTree.py",
line 1254, in close

self._parser.Parse("", 1) # end of data
xml.parsers.expat
.
ExpatError
:
no element found: line 1, column 0
'''''''''''''''''''''''''''''''''''''''

and 2) without the .py ending
'''''''''''''''''''''''''''''''''''''''
v.krige --help
No GRASS-python library found
'''''''''''''''''''''''''''''''''''''''

I also tried to run my own script without the .py ending and with --help:
'''''''''''''''''''''''''''''''''''''''
pythontest_l --help
Traceback (most recent call last):
   File "C:\OSGeo4W\apps\grass\grass-6.5.svn\scripts\pythonte
st_l.py", line 42, in <module>
     import grass.script as grass
ImportError: No module named grass.script
'''''''''''''''''''''''''''''''''''''''

What is the normal way to run a python script in windows, with or without the .py ending?

The main python on my Windows 7 and in the environemental variabels (Path) is C:\Python27
I need to run the script using my Windows python as there are some addtionaly python
modules my script depends on...

Thank you,

/Johannes

Am 05.12.2011 17:52, schrieb Glynn Clements:

Johannes Radinger wrote:

self._parser.Parse("", 1) # end of data
xml.parsers.expat
.
ExpatError
:
no element found: line 1, column 0
''''''''''''''''''''''''''''

I don't know what that exactly means?? I tried to compile the script
with two different line endings (UNIX coding and Windows coding) but
with similar result. So I don't know what is causing the problem!!

It means that it tried to generate a wxPython GUI for the options, the
code which generates the GUI executed the command with the
--interface-description flag to get a list of the options in XML
format, then passed the output to the Expat XML parser. Unfortunately,
the command failed to execute, so no XML was generated, and Expat
complains about not receiving valid XML.

IOW, the error message is accurate but quite useless. To get useful
information, you'll need to run the script manually from the command
line. Try running it with the --help option initially.

Johannes Radinger wrote:

I tried to run the script now manually with --help
from the command line. For simplicicity I only tried
v.krige.py, a python script that already comes with
the GRASS 6.5 SVN install.

v.krige.py isn't a normal Python script; it has its own GUI.

I also tried to run my own script without the .py ending and with --help:
'''''''''''''''''''''''''''''''''''''''
pythontest_l --help
Traceback (most recent call last):
   File "C:\OSGeo4W\apps\grass\grass-6.5.svn\scripts\pythonte
st_l.py", line 42, in <module>
     import grass.script as grass
ImportError: No module named grass.script
'''''''''''''''''''''''''''''''''''''''

You need:

  set PYTHONPATH=%GISBASE%\etc\python;%PYTHONPATH%

7.0 does this automatically, but 6.x doesn't.

What is the normal way to run a python script in windows, with or
without the .py ending?

I don't know. GRASS 6.x, Windows, and Python isn't a particularly
well-tested combination.

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

Hello,

I tried no to put 'set PYTHONPATH=%GISBASE%\etc\python;%PYTHONPATH%'
into the env.bat file of my selfcompiled GRASS6.5SVN on Windows.
Anyway it took me a while to get the 'real' correct line I think (as mentioned in the wiki)

In the env.bat file (C:\\OSGeo4W\apps\grass\grass-6.5.svn\etc\env.bat)
there are now following lines:

set GISBASE=%OSGEO4W_ROOT%\apps\grass\grass-6.5.svn
set GRASS_SH=%OSGEO4W_ROOT%\apps\msys\bin\sh.exe
set GRASS_WISH=%OSGEO4W_ROOT%\bin\wish.exe
set GRASS_PYTHON=%OSGEO4W_ROOT%\bin\python.exe
set GRASS_PROJSHARE=%OSGEO4W_ROOT%\share\proj
set GRASS_HTML_BROWSER=explorer
set PATH=%OSGEO4W_ROOT%\apps\grass\grass-6.5.svn\bin;%OSGEO4W_ROOT%\apps\grass\grass-6.5.svn\lib;%PATH%
set PYTHONPATH=%OSGEO4W_ROOT%\apps\Python25;%PYTHONPATH%

is that correct so far???
It seems that now a least the grass.script is found...but I still get
an erro when I want to call a python module/add on/script (with --help) from the GRASS commands console in the GRASS GUI:

(Tue Dec 13 15:36:48 2011)
pythontest_l --help
Traceback (most recent call last):
  File "C:\OSGeo4W\apps\grass\grass-6.5.svn\scripts\pythonte
st_l.py", line 42, in <module>
    import grass.script as grass
  File "c:\OSGeo4W\apps\grass\grass-6.5.svn\etc\python\grass
\script\__init__.py", line 1, in <module>
    from core import *
  File "c:\OSGeo4W\apps\grass\grass-6.5.svn\etc\python\grass
\script\core.py", line 31, in <module>
    import subprocess
  File "C:\OSGeo4W\apps\Python25\lib\subprocess.py", line
376, in <module>
    import threading
  File "C:\OSGeo4W\apps\Python25\lib\threading.py", line 13,
in <module>
    from collections import deque
ImportError: No module named collections
(Tue Dec 13 15:36:48 2011) Command finished (0 sec)

Is there anything more I can check? It seems that grass.script needs
a via subprocess a module called collections which isn't included in the python25 from the osgeo4w framework... do I understand that error correctly?

Just another question: Is it possible to use also my "own" python windows installation. Like I want to call my own add-on/script which includes g.parser and is compiled with the source. This script needs to load other pyhton modules which don't come with the osgeo-python. I script of this type is working on my Mac without any problems...hopefully it will also work on windows...
                   
Thank you,

Johannes

-------- Original-Nachricht --------

Datum: Wed, 7 Dec 2011 21:23:13 +0000
Von: Glynn Clements <glynn@gclements.plus.com>
An: Johannes Radinger <JRadinger@gmx.at>
CC: grass-dev@lists.osgeo.org, grass-windows@lists.osgeo.org
Betreff: Re: [GRASS-windows] compiling WINGrass Python Scripts - ExpatError

Johannes Radinger wrote:

> I tried to run the script now manually with --help
> from the command line. For simplicicity I only tried
> v.krige.py, a python script that already comes with
> the GRASS 6.5 SVN install.

v.krige.py isn't a normal Python script; it has its own GUI.

> I also tried to run my own script without the .py ending and with
--help:
> '''''''''''''''''''''''''''''''''''''''
> pythontest_l --help
> Traceback (most recent call last):
> File "C:\OSGeo4W\apps\grass\grass-6.5.svn\scripts\pythonte
> st_l.py", line 42, in <module>
> import grass.script as grass
> ImportError: No module named grass.script
> '''''''''''''''''''''''''''''''''''''''

You need:

  set PYTHONPATH=%GISBASE%\etc\python;%PYTHONPATH%

7.0 does this automatically, but 6.x doesn't.

> What is the normal way to run a python script in windows, with or
> without the .py ending?

I don't know. GRASS 6.x, Windows, and Python isn't a particularly
well-tested combination.

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

--
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!
Jetzt informieren: http://www.gmx.net/de/go/freephone

Johannes Radinger wrote:

I tried no to put 'set PYTHONPATH=%GISBASE%\etc\python;%PYTHONPATH%'
into the env.bat file of my selfcompiled GRASS6.5SVN on Windows.
Anyway it took me a while to get the 'real' correct line I think (as mentioned in the wiki)

In the env.bat file (C:\\OSGeo4W\apps\grass\grass-6.5.svn\etc\env.bat)
there are now following lines:

set GISBASE=%OSGEO4W_ROOT%\apps\grass\grass-6.5.svn
set GRASS_SH=%OSGEO4W_ROOT%\apps\msys\bin\sh.exe
set GRASS_WISH=%OSGEO4W_ROOT%\bin\wish.exe
set GRASS_PYTHON=%OSGEO4W_ROOT%\bin\python.exe
set GRASS_PROJSHARE=%OSGEO4W_ROOT%\share\proj
set GRASS_HTML_BROWSER=explorer
set PATH=%OSGEO4W_ROOT%\apps\grass\grass-6.5.svn\bin;%OSGEO4W_ROOT%\apps\grass\grass-6.5.svn\lib;%PATH%
set PYTHONPATH=%OSGEO4W_ROOT%\apps\Python25;%PYTHONPATH%

is that correct so far???

No. If GISBASE isn't defined at that point, try:

  set PYTHONPATH=%OSGEO4W_ROOT%\apps\grass\grass-6.5.svn\etc\python;%PYTHONPATH%

PYTHONPATH shouldn't include the directory where Python itself is
installed. PYTHONHOME is used for that, e.g.:

  set PYTHONHOME=%OSGEO4W_ROOT%\apps\Python25

ImportError: No module named collections

This error may be caused by a broken Python installation or a missing
or incorrect PYTHONHOME setting.

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