MONAILabel icon indicating copy to clipboard operation
MONAILabel copied to clipboard

Monailabel cann't run correctly in windows 11

Open Xu-Charles opened this issue 1 year ago • 6 comments

Discussed in https://github.com/Project-MONAI/MONAILabel/discussions/1793

Originally posted by Xu-Charles December 10, 2024 I have python 3.9.20 environment with PyTorch and CUDA installed. cuda version :12.4

(monailabel) C:\Users\Administrator>python Python 3.9.20 (main, Oct 3 2024, 07:38:01) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.

import torch print(torch.cuda.is_available()) True

But, I get the following error when running monailabel:

(monailabel) C:\Users\Administrator>monailabel Using PYTHONPATH=C:\ProgramData\Anaconda3\envs; "" Traceback (most recent call last): File "C:\ProgramData\Anaconda3\envs\monailabel\lib\runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None,

File "C:\ProgramData\Anaconda3\envs\monailabel\lib\runpy.py", line 87, in _run_code exec(code, run_globals)

File "C:\ProgramData\Anaconda3\envs\monailabel\lib\site-packages\monailabel\main.py", line 24, in from monailabel.config import settings

File "C:\ProgramData\Anaconda3\envs\monailabel\lib\site-packages\monailabel\config.py", line 23, in class Settings(BaseSettings):

File "C:\ProgramData\Anaconda3\envs\monailabel\lib\site-packages\monailabel\config.py", line 109, in Settings if is_package_installed("SAM-2")

File "C:\ProgramData\Anaconda3\envs\monailabel\lib\site-packages\monailabel\config.py", line 20, in is_package_installed return name in sorted(x.name for x in distributions())

File "C:\ProgramData\Anaconda3\envs\monailabel\lib\site-packages\monailabel\config.py", line 20, in return name in sorted(x.name for x in distributions())

AttributeError: 'PathDistribution' object has no attribute 'name'

Xu-Charles avatar Dec 10 '24 10:12 Xu-Charles

The issue is not that you use Windows11 but that you use Python-3.9.

I have run into the same issue. The problem was easy to fix (just use get method and tweak the sorting), but then when I noticed that there were further issues (SAM is not supported on Python 3.9) then I just gave up.

The error happens when you import MONAILabel, so it seems MONAILabel is not tested at all with Python-3.9 (or the failure is ignored), so I'm not sure if MONAILabel is supported on Python-3.9.

lassoan avatar Dec 10 '24 12:12 lassoan

Try: pip install importlib_metadata==8.4.0 if works, then please share the existing package version details for the above.

SachidanandAlle avatar Dec 10 '24 15:12 SachidanandAlle

is all good?

SachidanandAlle avatar Dec 16 '24 18:12 SachidanandAlle

If it helps at all, for me, with Python-3.9 MONAILabel failed on this line:

https://github.com/Project-MONAI/MONAILabel/blob/1fe0e8f373a5f7a613d511aa2ab02946c67d6c04/monailabel/config.py#L20

I've tried installing various importlib_metadata versions but in the end I've fixed the issue by changing the code to this:

return name in (x.metadata.get('Name') for x in distributions())

(It seems that I removed the sorting, I don't know why, maybe that was causing some issue, too, and you probably don't really need the sorting anyway)

Since then I decided to switch to Python-3.10, so I did not investigate Python-3.9 any further.

lassoan avatar Dec 16 '24 18:12 lassoan

https://github.com/Project-MONAI/MONAILabel/pull/1800

SachidanandAlle avatar Dec 16 '24 18:12 SachidanandAlle

@lassoan Hello, prof. lassoan. I had the same problem, and based on your suggestion, I changed the corresponding code of config. py to "return name in (x.metadata.get('Name') for x in distributions())". I had no problem when I typed in 'monailabel'. Subsequently, I downloaded the app and dataset, and the code displayed in the Anaconda Prompt is shown in the attached image. However, when I went into 3D Slicer, monailabel failed to carry out the automatic segmentation, and there were no Models to choose from under Auto Segmentation. If possible, I would like to ask you how I should resolve this issue. Thank you!

Image Image Image

linjy66 avatar Mar 26 '25 05:03 linjy66