<div dir="ltr"><div dir="ltr">Hi, <br><div><br><div class="gmail_quote"><div dir="ltr">pá 19. 10. 2018 v 17:18 odesílatel Martin Landa <<a href="mailto:landa.martin@gmail.com">landa.martin@gmail.com</a>> napsal:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
pá 19. 10. 2018 v 16:45 odesílatel Markus Neteler <<a href="mailto:neteler@osgeo.org" target="_blank">neteler@osgeo.org</a>> napsal:<br>
> we are currently writing a Python script which needs to import some<br>
> heavy external libraries.<br>
<br>
if I understand well, a lazy import could help<br>
<br>
"""<br>
def main:<br>
    from mylib import xyz<br>
    ...<br>
<br>
   return 0<br>
<br>
if __name__ == "__main__":<br>
    opt, flg = grass.parser()<br>
    sys.exit(main())<br>
"""<br>
</blockquote><br></div><div class="gmail_quote">In my  AddOn [1], I followed exactly this approach to avoid double import of TensorFlow. <br></div><div class="gmail_quote"><br></div><div class="gmail_quote">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. <br></div><div class="gmail_quote"><br></div><div class="gmail_quote">[1] <a href="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">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</a><br></div></div></div></div>