SBU-BMI / wsinfer

🔥 🚀 Blazingly fast pipeline for patch-based classification in whole slide images
https://wsinfer.readthedocs.io
Apache License 2.0
56 stars 9 forks source link

[BUG] setting openslide backend without installing openslide raises unhelpful error #170

Closed kaczmarj closed 1 year ago

kaczmarj commented 1 year ago

running a fresh install of wsinfer and attempting to use openslide backend raises an error.

pip install wsinfer==0.4.0
wsinfer --backend=openslide run --help

here is the error traceback:

INFO:wsinfer.wsi:Setting backend to openslide
Traceback (most recent call last):
  File "/tmp/foo/venv/bin/wsinfer", line 8, in <module>
    sys.exit(cli())
  File "/tmp/foo/venv/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/tmp/foo/venv/lib/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/tmp/foo/venv/lib/python3.10/site-packages/click/core.py", line 1685, in invoke
    super().invoke(ctx)
  File "/tmp/foo/venv/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/tmp/foo/venv/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/tmp/foo/venv/lib/python3.10/site-packages/wsinfer/cli/cli.py", line 44, in cli
    set_backend(backend)
  File "/tmp/foo/venv/lib/python3.10/site-packages/wsinfer/wsi.py", line 57, in set_backend
    WSI = openslide.OpenSlide
NameError: name 'openslide' is not defined

in the wsi.py file and set_backend function, we should test if openslide is available before setting the backend. if it is not available, we should fail loudly and tell the user to install openslide-python if they want to use openslide backend. it is possible that the user has already installed openslide-python but it cannot be imported because it cannot find libopenslide (the compiled library). we should add a debug log message if openslide-python is installed but libopenslide cannot be installed