<div dir="ltr"><div>Hi Markus,<br><br></div><div>going back to list because it is apparently a general problem. The answer is no. I haven't resolved this.<br><br></div><div>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).<br>

<br></div><div>The error is:<br><br>...lib/ctypes_loader.py", line 71, in load<br>    raise ImportError,e<br>ImportError: <a href="http://libgrass_datetime.7.1.svn.so">libgrass_datetime.7.1.svn.so</a>: cannot open shared object file: No such file or directory<br>

</div><div><br></div><div>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.<br>

<br></div><div>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]<br>

<br></div><div>Is this something library loader in GRASS should take care of?<br><br></div><div>Vaclav<br></div><div><br>[1] <a href="http://stackoverflow.com/questions/856116/changing-ld-library-path-at-runtime-for-ctypes">http://stackoverflow.com/questions/856116/changing-ld-library-path-at-runtime-for-ctypes</a><br>

[2] <a href="https://docs.python.org/2/library/ctypes.html">https://docs.python.org/2/library/ctypes.html</a><br>[3] <a href="http://bugs.python.org/issue2936">http://bugs.python.org/issue2936</a><br><br></div></div><div class="gmail_extra">

<br><br><div class="gmail_quote">On Thu, May 8, 2014 at 5:09 PM, Markus Neteler <span dir="ltr"><<a href="mailto:neteler@osgeo.org" target="_blank">neteler@osgeo.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

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


> [2] <a href="http://grasswiki.osgeo.org/wiki/GRASS_and_Python#Creating_Python_scripts_that_call_GRASS_functionality_from_outside" target="_blank">http://grasswiki.osgeo.org/wiki/GRASS_and_Python#Creating_Python_scripts_that_call_GRASS_functionality_from_outside</a><br>


> (BTW, these to sections could be merged together.)<br>
><br>
</div></div>> _______________________________________________<br>
> grass-dev mailing list<br>
> <a href="mailto:grass-dev@lists.osgeo.org">grass-dev@lists.osgeo.org</a><br>
> <a href="http://lists.osgeo.org/mailman/listinfo/grass-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/grass-dev</a><br>
</blockquote></div><br></div>