Hi,

pá 19. 10. 2018 v 17:18 odesílatel Martin Landa <landa.mar...@gmail.com>
napsal:

> pá 19. 10. 2018 v 16:45 odesílatel Markus Neteler <nete...@osgeo.org>
> napsal:
> > 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()
>     sys.exit(main())
> """
>

In my  AddOn [1], I followed exactly this approach to avoid double import
of TensorFlow.

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.

[1]
https://trac.osgeo.org/grass/browser/grass-addons/grass7/imagery/i.ann.maskrcnn/i.ann.maskrcnn.train/i.ann.maskrcnn.train.py?rev=72730#L181
_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-dev

Reply via email to