[GRASS-dev] getting SWIG/Python to work

A couple of issues here:

should "./configure --with-python" trigger make swig/python somehow?
(currently you have to manually run make)
Running make in the swig/ dir is a no-op.
See missing Python.h problem below, check for that too?

As per the readme, I had to install the 'swig' package to get going.
Add check for [-x `which swig`] to ./configure if --with-python?
(make exited with error the first time as it was missing)

make distclean doesn't clean these: (they are auto-generated by Makefile)
? interfaces/dig_structs.i
? interfaces/gisdefs.i
? interfaces/vect.i

this patch ok?

Index: swig/python/interfaces/Makefile

RCS file: /home/grass/grassrepository/grass6/swig/python/interfaces/Makefile,v
retrieving revision 1.7
diff -u -r1.7 Makefile
--- swig/python/interfaces/Makefile 14 May 2007 10:03:06 -0000 1.7
+++ swig/python/interfaces/Makefile 17 May 2007 04:19:38 -0000
@@ -13,3 +13,5 @@
        echo "/* auto-generate swig typedef file */" > vect.i
        cat ../../../include/Vect.h | grep -v 'V1_\|V2_' >> vect.i

+distclean:
+ -rm -f gisdefs.i dig_structs.i vect.i

grass63/swig/python$ make
Makefile:21: warning: overriding commands for target `clean'
../../include/Make/Rules.make:34: warning: ignoring old commands for target `clean'
gcc -c -fpic -I/usr/include/python2.3 -I./ -I/usr/local/src/grass/grass63/dist.i686-pc-linux-gnu/include python_grass6_wrap.c
python_grass6_wrap.c:22:20: Python.h: No such file or directory
python_grass6_wrap.c:622: error: syntax error before "PyObject_HEAD"
python_grass6_wrap.c:622: warning: no semicolon at end of struct or union
python_grass6_wrap.c:625: error: syntax error before '}' token
python_grass6_wrap.c:625: warning: data definition has no type or storage class
python_grass6_wrap.c:630: error: syntax error before '*' token
python_grass6_wrap.c: In function `PySwigObject_print':
python_grass6_wrap.c:633: error: `v' undeclared (first use in this function)
python_grass6_wrap.c:633: error: (Each undeclared identifier is reported only once
python_grass6_wrap.c:633: error: for each function it appears in.)
python_grass6_wrap.c:634: error: `fp' undeclared (first use in this function)
python_grass6_wrap.c: At top level:
python_grass6_wrap.c:641: error: syntax error before '*' token
python_grass6_wrap.c:642: error: syntax error before '*' token
python_grass6_wrap.c: In function `PySwigObject_repr':
python_grass6_wrap.c:645: error: `v' undeclared (first use in this function)
python_grass6_wrap.c:646: warning: return makes pointer from integer without a cast
python_grass6_wrap.c: At top level:
python_grass6_wrap.c:649: error: syntax error before '*' token
python_grass6_wrap.c:650: error: syntax error before '*' token
[...]
[...]
[...]

$ locate Python.h
[nothing]

$ apt-file search Python.h | grep -v Python.html
libsidl-dev: usr/include/sidl_Python.h
python2.1-dev: usr/include/python2.1/Python.h
python2.2-dev: usr/include/python2.2/Python.h
python2.3-dev: usr/include/python2.3/Python.h
python2.4-dev: usr/include/python2.4/Python.h

$ ls -l /usr/bin/python
... /usr/bin/python -> python2.3

# apt-get install python2.3-dev
[whiz,bang,whirl]

grass63/swig/python$ make
Makefile:21: warning: overriding commands for target `clean'
../../include/Make/Rules.make:34: warning: ignoring old commands for target `clean'
gcc -c -fpic -I/usr/include/python2.3 -I./ -I/usr/local/src/grass/grass63/dist.i686-pc-linux-gnu/include python_grass6_wrap.c
python_grass6_wrap.c: In function `_wrap_Categories_labels_get':
python_grass6_wrap.c:9151: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_Key_Value_key_get':
python_grass6_wrap.c:12128: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_Key_Value_value_get':
python_grass6_wrap.c:12189: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_Option_opts_get':
python_grass6_wrap.c:12511: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_Option_descs_get':
python_grass6_wrap.c:12760: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_Option_answers_get':
python_grass6_wrap.c:12915: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_G_list':
python_grass6_wrap.c:26292: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_G__ls':
python_grass6_wrap.c:26672: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_G_available_mapsets':
python_grass6_wrap.c:27240: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_G_tokenize':
python_grass6_wrap.c:34387: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_SITE_ATT_str_get':
python_grass6_wrap.c:49748: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
ld -shared -L/usr/local/src/grass/grass63/dist.i686-pc-linux-gnu/lib -lgrass_I -lgrass_Iortho -lgrass_bitmap -lgrass_btree -lgrass_cdhc -lgrass_datetime -lgrass_dbmibase -lgrass_dbmiclient -lgrass_dbmidriver -lgrass_dbstubs -lgrass_dgl -lgrass_display -lgrass_dspf -lgrass_edit -lgrass_form -lgrass_g3d -lgrass_gis -lgrass_gmath -lgrass_gproj -lgrass_interpdata -lgrass_interpfl -lgrass_linkm -lgrass_qtree -lgrass_raster -lgrass_rowio -lgrass_rtree -lgrass_segment -lgrass_shape -lgrass_sites -lgrass_symb -lgrass_trans -lgrass_vask -lgrass_vect -lgrass_psdriver python_grass6_wrap.o -o _python_grass6.so

Are those incompatible pointer type warnings meaningful?

grass63/swig/python$ ls -l python_grass6.py _python_grass6.so
... 1030944 May 17 16:52 _python_grass6.so
... 277076 May 17 16:47 python_grass6.py
[success!]

"make -C interfaces/" didn't run. (why not?) I had to go into the subdir
and run make manually to generate gisdefs.i, dig_structs.i, and vect.i.

from the README:
------------------------
How to use it?
--------------

import python_grass6
GRASS functions will be available in this module.
Eg:
        import python_grass6
        mapset=python_grass6.G_mapset()
        print mapset
-------------------------

G63> cd swig/python/
G63> python

Python 2.3.5 (#2, Oct 16 2006, 19:19:48)
[GCC 3.3.5 (Debian 1:3.3.5-13)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import python_grass6

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "python_grass6.py", line 5, in ?
    import _python_grass6
ImportError: ./_python_grass6.so: undefined symbol: Vect_snap_lines_list

swig/python$ grep interfaces *.i
python_grass6.i:%include "interfaces/gis.i"
python_grass6.i:%include "interfaces/gisdefs.i"
python_grass6.i:%include "interfaces/imagery.i"
python_grass6.i:%include "interfaces/imagedefs.i"
python_grass6.i:%include "interfaces/vect.i"
python_grass6.i:%include "interfaces/dig_structs.i"
python_grass6.i:%include "interfaces/dig_types.i"

swig/python$ grep Vect_snap_lines_list python_grass6.py
Vect_snap_lines_list = _python_grass6.Vect_snap_lines_list

swig/python$ grep Vect_snap_lines_list interfaces/*.i
interfaces/vect.i:void Vect_snap_lines_list (struct Map_info *, struct ilist *, double, struct Map_info *, FILE *);

swig/python$ ldd _python_grass6.so | grep vect
  libgrass_vect.so => /usr/lib/grass/lib/libgrass_vect.so (0x40271000)

ahh, it is using /usr/lib/grass/lib/ (Debian 6.0.2 package install) not
/usr/src/grass/grass63/dist.i686-pc-linux-gnu/lib build dir.

swig/python/Makefile:
...
LDFLAGS=-shared -L$(ARCH_LIBDIR) -lgrass_I -lgrass_Iortho [...]

why doesn't it respect -L$(ARCH_LIBDIR) as other things calling
  include $(MODULE_TOPDIR)/include/Make/Lib.make
do??
I've always had /usr/lib/grass/lib/ there, never a problem before.
(Debian's libgrass package is a needed prereq for the libgdal1-1.3.1-grass
[the GDAL GRASS plugin] and qgis-plugin-grass packages)

# apt-get remove libgrass

swig/python$ make clean && make && make -C interfaces
[ok]

swig/python$ ldd _python_grass6.so | grep vect
        libgrass_vect.so => not found

mmmph!

thanks,
Hamish

On Thu, May 17, 2007 at 05:35:08PM +1200, Hamish wrote:

A couple of issues here:

should "./configure --with-python" trigger make swig/python somehow?
(currently you have to manually run make)
Running make in the swig/ dir is a no-op.
See missing Python.h problem below, check for that too?

As per the readme, I had to install the 'swig' package to get going.
Add check for [-x `which swig`] to ./configure if --with-python?
(make exited with error the first time as it was missing)

I think that configure[.in] should be improved in this regard.

make distclean doesn't clean these: (they are auto-generated by Makefile)
? interfaces/dig_structs.i
? interfaces/gisdefs.i
? interfaces/vect.i

this patch ok?

No - these files should be better autogenerated like the other *.i
files in that directory.

...

grass63/swig/python$ make
Makefile:21: warning: overriding commands for target `clean'
../../include/Make/Rules.make:34: warning: ignoring old commands for target `clean'
gcc -c -fpic -I/usr/include/python2.3 -I./ -I/usr/local/src/grass/grass63/dist.i686-pc-linux-gnu/include python_grass6_wrap.c
python_grass6_wrap.c:22:20: Python.h: No such file or directory

[...]

$ locate Python.h
[nothing]

/usr/include/python2.4/Python.h

Perhaps we can borrow this from GDAL where things are already solved.

grass63/swig/python$ make
Makefile:21: warning: overriding commands for target `clean'
../../include/Make/Rules.make:34: warning: ignoring old commands for target `clean'
gcc -c -fpic -I/usr/include/python2.3 -I./ -I/usr/local/src/grass/grass63/dist.i686-pc-linux-gnu/include python_grass6_wrap.c
python_grass6_wrap.c: In function `_wrap_Categories_labels_get':
python_grass6_wrap.c:9151: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_Key_Value_key_get':
python_grass6_wrap.c:12128: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_Key_Value_value_get':
python_grass6_wrap.c:12189: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_Option_opts_get':
python_grass6_wrap.c:12511: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_Option_descs_get':
python_grass6_wrap.c:12760: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_Option_answers_get':
python_grass6_wrap.c:12915: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_G_list':
python_grass6_wrap.c:26292: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_G__ls':
python_grass6_wrap.c:26672: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_G_available_mapsets':
python_grass6_wrap.c:27240: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_G_tokenize':
python_grass6_wrap.c:34387: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_SITE_ATT_str_get':
python_grass6_wrap.c:49748: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
ld -shared -L/usr/local/src/grass/grass63/dist.i686-pc-linux-gnu/lib -lgrass_I -lgrass_Iortho -lgrass_bitmap -lgrass_btree -lgrass_cdhc -lgrass_datetime -lgrass_dbmibase -lgrass_dbmiclient -lgrass_dbmidriver -lgrass_dbstubs -lgrass_dgl -lgrass_display -lgrass_dspf -lgrass_edit -lgrass_form -lgrass_g3d -lgrass_gis -lgrass_gmath -lgrass_gproj -lgrass_interpdata -lgrass_interpfl -lgrass_linkm -lgrass_qtree -lgrass_raster -lgrass_rowio -lgrass_rtree -lgrass_segment -lgrass_shape -lgrass_sites -lgrass_symb -lgrass_trans -lgrass_vask -lgrass_vect -lgrass_psdriver python_grass6_wrap.o -o _python_grass6.so

Are those incompatible pointer type warnings meaningful?

(expert wanted here)

grass63/swig/python$ ls -l python_grass6.py _python_grass6.so
... 1030944 May 17 16:52 _python_grass6.so
... 277076 May 17 16:47 python_grass6.py
[success!]

"make -C interfaces/" didn't run. (why not?) I had to go into the subdir
and run make manually to generate gisdefs.i, dig_structs.i, and vect.i.

No clue...

...

swig/python$ ldd _python_grass6.so | grep vect
  libgrass_vect.so => /usr/lib/grass/lib/libgrass_vect.so (0x40271000)

ahh, it is using /usr/lib/grass/lib/ (Debian 6.0.2 package install) not
/usr/src/grass/grass63/dist.i686-pc-linux-gnu/lib build dir.

swig/python/Makefile:
...
LDFLAGS=-shared -L$(ARCH_LIBDIR) -lgrass_I -lgrass_Iortho [...]

why doesn't it respect -L$(ARCH_LIBDIR) as other things calling
  include $(MODULE_TOPDIR)/include/Make/Lib.make
do??

No special reason. Please fix it.

I've always had /usr/lib/grass/lib/ there, never a problem before.
(Debian's libgrass package is a needed prereq for the libgdal1-1.3.1-grass
[the GDAL GRASS plugin] and qgis-plugin-grass packages)

# apt-get remove libgrass

swig/python$ make clean && make && make -C interfaces
[ok]

swig/python$ ldd _python_grass6.so | grep vect
        libgrass_vect.so => not found

mmmph!

Folks are kindly invited to fix the remaining problems :slight_smile:

Markus

Hamish:

> make distclean doesn't clean these: (they are auto-generated by
> Makefile) ? interfaces/dig_structs.i
> ? interfaces/gisdefs.i
> ? interfaces/vect.i
>
> this patch ok?

Markus:

No - these files should be better autogenerated like the other *.i
files in that directory.

Those ARE the auto-gen files. They don't get cleaned.

The other files which should be auto-generated but are currently not,
(and in the case of gis.i I notice out of date vs. gis.h) are:

dig_types.i
gis.i
imagedefs.i
imagery.i

is there any special rules for including of not including fns or
definitions? e.g. I see that G_warning and friends are skipped; why?

> grass63/swig/python$ make
> Makefile:21: warning: overriding commands for target `clean'
> ../../include/Make/Rules.make:34: warning: ignoring old commands for
> target `clean' gcc -c -fpic -I/usr/include/python2.3 -I./
> -I/usr/local/src/grass/grass63/dist.i686-pc-linux-gnu/include
> python_grass6_wrap.c python_grass6_wrap.c:22:20: Python.h: No such
> file or directory
[...]

> $ locate Python.h
> [nothing]

..

Perhaps we can borrow this from GDAL where things are already solved.

It just needs a little test compile in configure, like everything else?

> why doesn't it respect -L$(ARCH_LIBDIR) as other things calling
> include $(MODULE_TOPDIR)/include/Make/Lib.make
> do??

No special reason. Please fix it.

No, those lines are already included in the Makefile, but they don't
work. No idea how to fix it.

thanks,
Hamish

Hamish wrote on 05/17/2007 08:27 AM:

Hamish:
  

make distclean doesn't clean these: (they are auto-generated by
Makefile) ? interfaces/dig_structs.i
? interfaces/gisdefs.i
? interfaces/vect.i

this patch ok?
      

Markus:
  

No - these files should be better autogenerated like the other *.i
files in that directory.
    
Those ARE the auto-gen files. They don't get cleaned.

The other files which should be auto-generated but are currently not,
(and in the case of gis.i I notice out of date vs. gis.h) are:

dig_types.i
gis.i
imagedefs.i
imagery.i

Oh, sorry, I was mixing that up. So
- yes, should be cleaned
- the others should also be auto-generated

is there any special rules for including of not including fns or
definitions? e.g. I see that G_warning and friends are skipped; why?
  

Because SWIG starts wining about the definitions. I know nothing about
SWIG, so
no idea how to declare them. Of course, we need them.

grass63/swig/python$ make
Makefile:21: warning: overriding commands for target `clean'
../../include/Make/Rules.make:34: warning: ignoring old commands for
target `clean' gcc -c -fpic -I/usr/include/python2.3 -I./
-I/usr/local/src/grass/grass63/dist.i686-pc-linux-gnu/include
python_grass6_wrap.c python_grass6_wrap.c:22:20: Python.h: No such
file or directory
      

[...]

$ locate Python.h
[nothing]
      

..
  

Perhaps we can borrow this from GDAL where things are already solved.
    
It just needs a little test compile in configure, like everything else?
  

Probably yes.

why doesn't it respect -L$(ARCH_LIBDIR) as other things calling
  include $(MODULE_TOPDIR)/include/Make/Lib.make
do??
      

No special reason. Please fix it.
    
No, those lines are already included in the Makefile, but they don't
work. No idea how to fix it.
  

Needs to be investigated...

Markus

------------------
ITC -> dall'1 marzo 2007 Fondazione Bruno Kessler
ITC -> since 1 March 2007 Fondazione Bruno Kessler
------------------

On Thu, May 17, 2007 at 06:27:46PM +1200, Hamish wrote:
...

> > grass63/swig/python$ make
> > Makefile:21: warning: overriding commands for target `clean'
> > ../../include/Make/Rules.make:34: warning: ignoring old commands for
> > target `clean' gcc -c -fpic -I/usr/include/python2.3 -I./
> > -I/usr/local/src/grass/grass63/dist.i686-pc-linux-gnu/include
> > python_grass6_wrap.c python_grass6_wrap.c:22:20: Python.h: No such
> > file or directory
> [...]
>
> > $ locate Python.h
> > [nothing]
..
> Perhaps we can borrow this from GDAL where things are already solved.

It just needs a little test compile in configure, like everything else?

I just found the GDAL ticket:
http://trac.osgeo.org/gdal/ticket/1508

with solution:
http://trac.osgeo.org/gdal/changeset/10911

Looks like a simple fix.

Markus

I am trying to build grass in Solaris and looks like make goes through without any errors... but make install says try make first..

ans help will be appreciated

bash-3.00# make
test -d /usr/local/grass-6.2.1 || mkdir -p -m 755 /usr/local/grass-6.2.1
tar cBf - demolocation | (cd /usr/local/grass-6.2.1/ ; tar xBfo - ) 2>/dev/null
chmod 744 install-sh
`lib' is up to date.
`db' is up to date.
`display' is up to date.
`doc' is up to date.
`gem' is up to date.
`general' is up to date.
`gui' is up to date.
`imagery' is up to date.
`misc' is up to date.
`paint' is up to date.
`ps' is up to date.
`raster' is up to date.
`raster3d' is up to date.
`scripts' is up to date.
`sites' is up to date.
`tools' is up to date.
`vector' is up to date.
`visualization' is up to date.
`man' is up to date.
if [ 1 -eq 1 ] ; then make locale; fi
`locale' is up to date.
cp -f AUTHORS COPYING README REQUIREMENTS.html /usr/local/grass-6.2.1/
#cp -f /usr/local/bin/grass62 /usr/local/grass-6.2.1/grass62.tmp
cat: cannot open ../dist.i386-pc-solaris2.10/etc/VERSIONNUMBER
build_html_index.sh
*.*.html: No such file or directory
Generating HTML manual pages index (help system)...
Generated HTML docs in ../dist.i386-pc-solaris2.10/docs/html/index.html
----------------------------------------------------------------------
Following modules are missing the 'description.html' file in src code:
----------------------------------------------------------------------
GRASS GIS compilation log
-------------------------
Started compilation: Fri May 18 09:56:34 PDT 2007
--
Errors in:
--
Finished compilation: Fri May 18 09:56:34 PDT 2007
(In case of errors please change into the directory with error and run 'make')

bash-3.00#make install
echo /usr/local/bin/grass62
/usr/local/bin/grass62
ERROR: GRASS has not been compiled. Try "make" first.
  Installation aborted, exiting Make.
bash-3.00#

Prameet,

Can you run grass as

# ./bin.i386-pc-solaris2.10/grass63

?

Daniel.

On 5/18/07, Prameet Chhabra - Sun Microsystems - Newark United States
<Prameet.Chhabra@sun.com> wrote:

I am trying to build grass in Solaris and looks like make goes through
without any errors... but make install says try make first..

ans help will be appreciated

bash-3.00# make
test -d /usr/local/grass-6.2.1 || mkdir -p -m 755 /usr/local/grass-6.2.1
tar cBf - demolocation | (cd /usr/local/grass-6.2.1/ ; tar xBfo - )
2>/dev/null
chmod 744 install-sh
`lib' is up to date.
`db' is up to date.
`display' is up to date.
`doc' is up to date.
`gem' is up to date.
`general' is up to date.
`gui' is up to date.
`imagery' is up to date.
`misc' is up to date.
`paint' is up to date.
`ps' is up to date.
`raster' is up to date.
`raster3d' is up to date.
`scripts' is up to date.
`sites' is up to date.
`tools' is up to date.
`vector' is up to date.
`visualization' is up to date.
`man' is up to date.
if [ 1 -eq 1 ] ; then make locale; fi
`locale' is up to date.
cp -f AUTHORS COPYING README REQUIREMENTS.html /usr/local/grass-6.2.1/
#cp -f /usr/local/bin/grass62 /usr/local/grass-6.2.1/grass62.tmp
cat: cannot open ../dist.i386-pc-solaris2.10/etc/VERSIONNUMBER
build_html_index.sh
*.*.html: No such file or directory
Generating HTML manual pages index (help system)...
Generated HTML docs in ../dist.i386-pc-solaris2.10/docs/html/index.html
----------------------------------------------------------------------
Following modules are missing the 'description.html' file in src code:
----------------------------------------------------------------------
GRASS GIS compilation log
-------------------------
Started compilation: Fri May 18 09:56:34 PDT 2007
--
Errors in:
--
Finished compilation: Fri May 18 09:56:34 PDT 2007
(In case of errors please change into the directory with error and run
'make')

bash-3.00#make install
echo /usr/local/bin/grass62
/usr/local/bin/grass62
ERROR: GRASS has not been compiled. Try "make" first.
  Installation aborted, exiting Make.
bash-3.00#

_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

--
-- Daniel Calvelo Aros