[GRASS-dev] Calling GRASS from outside: cannot open shared object file

Vaclav Petras wenzeslaus at gmail.com
Thu May 8 20:55:31 PDT 2014


Hi Markus,

going back to list because it is apparently a general problem. The answer
is no. I haven't resolved this.

Intro for others: currently, it is not possible to use ctypes API (and thus
PyGRASS) in standalone Python script which is not GRASS module (script
running outside GRASS session).

The error is:

...lib/ctypes_loader.py", line 71, in load
    raise ImportError,e
ImportError: libgrass_datetime.7.1.svn.so: cannot open shared object file:
No such file or directory

On Linux `print os.environ['LD_LIBRARY_PATH']` shows the path to GRASS libs
(`:/.../dist.../lib`). And explicit setting of this variable (without
leading `:`) does not change anything.

It seems that it is not possible to influence library loading by
LD_LIBRARY_PATH when the process is already running. [1] And ctypes does
not seem to have special support to handle path adding at runtime. [2, 3]

Is this something library loader in GRASS should take care of?

Vaclav

[1]
http://stackoverflow.com/questions/856116/changing-ld-library-path-at-runtime-for-ctypes
[2] https://docs.python.org/2/library/ctypes.html
[3] http://bugs.python.org/issue2936



On Thu, May 8, 2014 at 5:09 PM, Markus Neteler <neteler at osgeo.org> wrote:

> Hi Vaclav,
>
> did you ever resolve this issue? I have it now (ok, with some delay to
> your tests :-).
> Attached my script which is yours with a few minor additions.
>
> Would be glad to learn how to fix this issue:
>
> python ~/python_test_ctypes.py
> {'MAPSET': 'user1', 'GISDBASE': '/home/neteler/grassdata',
> 'LOCATION_NAME': 'nc_spm_08_grass7'}
> Raster maps:
> lsat5_1987_10 at landsat
> lsat5_1987_40 at landsat
> ...
> zero at user1
> horangle_01 at user1
> precip_annual at user1
> Traceback (most recent call last):
>   File "/home/neteler/python_test_ctypes.py", line 38, in <module>
>     import grass.lib.gis as gis
>   File
> "/home/neteler/software/grass71/dist.x86_64-unknown-linux-gnu/etc/python/grass/lib/gis.py",
> line 23, in <module>
>     _libs["grass_gis.7.1.svn"] = load_library("grass_gis.7.1.svn")
>   File
> "/home/neteler/software/grass71/dist.x86_64-unknown-linux-gnu/etc/python/grass/lib/ctypes_loader.py",
> line 55, in load_library
>     return self.load(path)
>   File
> "/home/neteler/software/grass71/dist.x86_64-unknown-linux-gnu/etc/python/grass/lib/ctypes_loader.py",
> line 71, in load
>     raise ImportError,e
> ImportError: libgrass_datetime.7.1.svn.so: cannot open shared object
> file: No such file or directory
> [neteler at oboe python_intro]$
>
> thanks
> Markus
>
>
> On Mon, Feb 18, 2013 at 6:41 PM, Vaclav Petras <wenzeslaus at gmail.com>
> wrote:
> > Hi,
> >
> > I've tried to use GRASS without starting it explicitly in Python. I've
> > used example from wiki [1] which works. However, when I tried to use
> > library functions through ctypes, I'm not able to import lib modules.
> > I've added these lines to the example:
> >
> > import grass.lib.gis as gis
> > print gis.G_location_path()
> >
> > and the import fails with and error:
> >
> > Traceback (most recent call last):
> >   File "python_test_ctypes.py", line 23, in <module>
> >     import grass.lib.gis as gis
> >   File
> "/home/vasek/dev/grass/trunk/dist.i686-pc-linux-gnu/etc/python/grass/lib/gis.py",
> > line 23, in <module>
> >     _libs["grass_gis.7.0.svn"] = load_library("grass_gis.7.0.svn")
> >   File
> "/home/vasek/dev/grass/trunk/dist.i686-pc-linux-gnu/etc/python/grass/lib/ctypes_loader.py",
> > line 55, in load_library
> >     return self.load(path)
> >   File
> "/home/vasek/dev/grass/trunk/dist.i686-pc-linux-gnu/etc/python/grass/lib/ctypes_loader.py",
> > line 72, in load
> >     raise ImportError,e
> > ImportError: libgrass_datetime.7.0.svn.so: cannot open shared object
> > file: No such file or directory
> >
> > I placed print path to the ctypes/loader.py file (line 71) and I get
> > this output:
> >
> > /home/vasek/dev/grass/trunk/dist.i686-pc-linux-gnu/lib/
> libgrass_gis.7.0.svn.so
> >
> > This file exists (checked on disk and also python code checks this in
> > the function load_library) and libgrass_datetime.7.0.svn.so exists in
> > the same folder, too. The output of print
> > os.environ['LD_LIBRARY_PATH'] is:
> >
> > :/home/vasek/dev/grass/trunk/dist.i686-pc-linux-gnu/lib
> >
> > Running this script in GRASS session works.
> >
> > Vaclav
> >
> >
> > [1]
> http://grasswiki.osgeo.org/wiki/Working_with_GRASS_without_starting_it_explicitly#Python_example
> > [2]
> http://grasswiki.osgeo.org/wiki/GRASS_and_Python#Creating_Python_scripts_that_call_GRASS_functionality_from_outside
> > (BTW, these to sections could be merged together.)
> >
> > _______________________________________________
> > grass-dev mailing list
> > grass-dev at lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/grass-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20140508/40d5634d/attachment-0001.html>


More information about the grass-dev mailing list