LungCTAnalyzer in macOS: missing os.startfile

@rbumm

In LungCTAnalyzer 2.49 in Slicer 5.0.2 in macOS 12.4 with Python 3.9.10, when generating PDF report: report is generated in LungCTAnalyzerReports but Python Interactor shows

modules/LungCTAnalyzer.py", line 843, in onCreatePDFReportButton
    os.startfile(reportPath.replace('/', '\\'))
AttributeError: module 'os' has no attribute 'startfile'

Seems os.startfile is Windows-specific, and macOS may need os.system("open myFile").

The error is not seen with Create CSV file (after PDF report generation).

Yes, that call is windows specific. It would be great if someone could contribute a fix to generalize the code.

https://docs.python.org/3/library/os.html#os.startfile

Thank you @pieper .

I think this fixed the problem.

@ashipde could you

image

in the extension manager tomorrow or the day after that, then update the Lung CT Analyzer and test again? I have no MAC or Linux available …

Thank you.

@rbumm Thank you for the quick-fix. The error does not appear, but on macOS, the generated PDF report is not opened automatically, which I believe is the intent. In error messages I see: The file /\Users\ashipde\Documents\LungCTAnalyzerReports\[redacted].pdf does not exist. But the file exists… seems backslashes are the issue (macOS/Unix using forward ones unlike Windows).

1 Like

Thank you. I removed the backslash generation in the PDF path for macOS and Linux.
Could you test again?

The file-missing error is gone after the latest fix. Interactor window shows Starting '/Users/ashipde/Documents/LungCTAnalyzerReports/[redacted].pdf' .... However, the PDF file does not auto-open. My system Python opens the file in PDF viewer app with subprocess.call(['open', '/Users/ashipde/Documents/LungCTAnalyzerReports/[redacted].pdf']), so not sure what may be the issue.

@ashipde please try if the same subprocess call opens the file in Slicer’s Python interactor. If it does not work then you may need to use the startup environment.

My mistake. The report file does auto-open as expected with the latest GitHub download of the extension. May be my extension uninstall/re-install was not done properly by me.

2 Likes