Import other libraries in HLA

Hi,

I am trying to import some libraries in the HLA. Easily accomplished, or so I thought, by

  1. Putting a lib folder next to my script
  2. pip install -r requirements.txt --target lib
  3. sys.path.append(str(Path(__file__).parent.absolute() / 'lib'))

And it is in fact easily accomplished. But the trouble apparently starts when the module I import wants to import something else. It seems all second level imports fail.

HighLevelAnalyzer.py", line 21, in <module>
    from construct import Struct

  File "C:\Program Files\Logic\resources\windows\pythonlibs\lib\site-packages\saleae\_module_space.py", line 244, in load_module
    self._inner_loader.exec_module(module)

  File "C:\project\lib\construct\__init__.py", line 22, in <module>
    from construct.core import *

As you can see it could apparently find lib/construct/__init__.py but that’s when it gets amnesia.

My investigation came to a stop when I found Program Files\Logic\resources\windows\pythonlibs\lib\site-packages\saleae\_module_space.py and realize you somehow are doing this on purpose.

The tip at Third party libraries with HLAs - #5 by bruff seems to be what I tried above, but that is a couple years old now.

Is there any way I can successfully import things? I don’t really care how much extra boilerplate I need so long as it works in the end.

Best regards

1 Like

Hi @aslakrin, we’ve done some testing internally, and it looks like it should work if you move your lib directory outside of the extension. Sorry for the trouble!

1 Like

Thanks that works perfectly! Didn’t see an email notification so didn’t think to check back until now.

Discovered “reload sources” does not reload the libraries, but can live with that.