DCBIA-OrthoLab / SlicerDentalModelSeg

This extension aims to provide a GUI for a deep-learning automated teeth segmentation tool that we developed at the University of North Carolina in Chapel Hill in collaboration with the University of Michigan in Ann Arbor.
Apache License 2.0
44 stars 10 forks source link

FIX : couldn't find CrownSegmentationcli.py #28

Closed GaelleLeroux closed 5 months ago

GaelleLeroux commented 6 months ago

Hi @allemangD !

I had the same problems we have with ALI_IOS on Windows. I need the full path to the CrownSegmentationcli.py file to run it in wsl. I've created a function based on Slicer's PYTHONPATH to find the file. What do you think ? If you're ok, I'll do the same thing on ALI_IOS after this merge.

Thank you ! Gaelle

allemangD commented 6 months ago

At a glance it looks like https://realpython.com/python-import/ has good information on the import system and search paths.

https://docs.python.org/3/reference/import.html is the reference documentation but it is difficult to read if you don't already understand it in detail. I suggest you review the realpython link.

The relevant section for this is Python's Import Path - but that entire page has valuable information and demonstrations.

GaelleLeroux commented 6 months ago

Adding the PYTHONPATH to my environment in WSL seems to work. When I manually add FlexReg in Slicer and do the step you suggested, it works fine. But when I try to run requirement.py (located in ALI/ALI_IOS_utils in the DCBIA repository), I can't find it, even though I see the file on the computer after downloading AutomatedTools as a user.

When I run a command in the python console of Slicer to get more details about the paths it knows that are linked to SlicerAutomatedDentalTools. I can see the path to ALI.py and some files in AREG_Method but I can't see any path with ALI_IOS_utils in it. I can't understand why it knows the path to Reader.py (located in ASO/ASO_Method_IOS_utils/ in the DCBIA repository) and not the requirement.py path. Do you have an explanation and how I can solve it ? image

Thank you !

allemangD commented 6 months ago

You'd access it from python via import ALI_IOS_utils.requirement, or you'd execute it via command line (assuming PYTHONPATH is set properly) with -m option like conda run ... python -m ALI_IOS_utils.requirement.

sys.modules contains only the modules that have already been loaded. If nothing has imported a module yet, it won't appear in sys.modules.

However if you inspect sys.path - or notice the location of modules like ALI, AMASSS, etc. - you'll see ..../qt-scripted-modules on the path. That's the root that's searched for modules; when you import or -m ALI_IOS_utils.requirement python will look at ..../qt-scripted-modules/ALI_IOS_utils/requirement.py.

GaelleLeroux commented 5 months ago

@allemangD

I think I did it, it works fine on my computer! Can you tell me if it's good and if so merge it?

Thank you !