How to access a package declared in Slicer extension from the python console?

I have a python package declared within the extension, and I can import it directly when accessing from the extension code. How can I import that extension in the Slicer python console?

I’ve done this before, I know it is possible, but I cannot find it in the hierarchies of slicer.modules.* etc.

Do you mean something like this?

self.showStatusMessage(' Importing lungmask AI ...')
try:
    import lungmask
except ModuleNotFoundError:
    self.showStatusMessage(' Installing lungmask AI ...')
    lungmaskPackage = "https://github.com/JoHof/lungmask/archive/master.zip"
    slicer.util.pip_install(lungmaskPackage)
    import lungmask

1 Like

With the help of @DeepaKrishnaswamy I figured this out.

To be more specific, I wanted to import this package:

Which is part of this extension:

Which is very simple once you know how to do it. I hope I will remember it for the next time!

from TCIABrowser import TCIAClient
2 Likes