[GRASS-dev] Python scripts in GRASS GIS: conditional loading of external libraries?
pesej.ondrek at gmail.com
Fri Oct 19 12:16:08 PDT 2018
pá 19. 10. 2018 v 17:18 odesílatel Martin Landa <landa.martin at gmail.com>
> pá 19. 10. 2018 v 16:45 odesílatel Markus Neteler <neteler at osgeo.org>
> > we are currently writing a Python script which needs to import some
> > heavy external libraries.
> if I understand well, a lazy import could help
> def main:
> from mylib import xyz
> return 0
> if __name__ == "__main__":
> opt, flg = grass.parser()
In my AddOn , I followed exactly this approach to avoid double import
If I remember correctly, libraries imported before the call of
`grass.parser()` are imported also during the installation through
`g.extension` because of checks or something and you really don't want to
import quite heavy TensorFlow (which is moreover printing some warnings
during the import on most of computers) making your installation slow. The
same applied to the double import when running the script.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the grass-dev