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

Glynn Clements glynn at gclements.plus.com
Mon May 12 15:23:15 PDT 2014


Vaclav Petras wrote:

> > Even if you can load the library, you probably aren't going to be able
> > to do much with it unless GISRC is set.
> 
> I hoped that this is what `grass.script.setup.init` is doing.

Fair enough.

However, that's going to be subject to a number of of chicken-and-egg
problems, of which LD_LIBRARY_PATH is only one (e.g. on Windows with a
"bundled" Python interpreter, running a Python script from outside
GRASS is going to use the system Python, not the bundled Python).

The safe solution is to first set up all of the environment variables
for a GRASS "session" then execute the "real" script with e.g. 
os.execv().

That should eliminate any issues with changes to environment variables
not taking effect. It should also ensure that the real script is
executed using any bundled Python.

To be honest, I'm not sure that setup.py belongs in lib/python. 
lib/init (alongside grass.py) seems more appropriate, as it's widely
understood that any code in that directory can't rely upon the usual
GRASS features.

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


More information about the grass-dev mailing list