# LungCTAnalyzer in macOS: missing os.startfile

**URL:** <https://discourse.slicer.org/t/lungctanalyzer-in-macos-missing-os-startfile/24058>\
**Category:** Support\
**Tags:** lungctanalyzer\
**Created:** [June 27, 2022, 1:22am UTC](https://discourse.slicer.org/t/lungctanalyzer-in-macos-missing-os-startfile/24058 "2022-06-27T01:22:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashipde](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ashipde/32/15695_2.png) [@ashipde](https://discourse.slicer.org/u/ashipde)\
**Post date:** [June 27, 2022, 1:22am UTC](https://discourse.slicer.org/t/lungctanalyzer-in-macos-missing-os-startfile/24058/1 "2022-06-27T01:22:01Z")

</div>

@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

```auto
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).

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [June 27, 2022, 4:42pm UTC](https://discourse.slicer.org/t/lungctanalyzer-in-macos-missing-os-startfile/24058/2 "2022-06-27T16:42:24Z")

</div>

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](https://docs.python.org/3/library/os.html#os.startfile)

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [June 27, 2022, 5:48pm UTC](https://discourse.slicer.org/t/lungctanalyzer-in-macos-missing-os-startfile/24058/3 "2022-06-27T17:48:59Z")

</div>

Thank you @pieper .

I think this [fixed the problem](https://github.com/rbumm/SlicerLungCTAnalyzer/commit/0a841f004673e96219e24cd75ccc5d4d6f29df00).

@ashipde could you

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/2/22a94f7b1d924bf0820239df34a5e996b21df25a.png)

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.

---

<div class="post-metadata">

**Author:** ![ashipde](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ashipde/32/15695_2.png) [@ashipde](https://discourse.slicer.org/u/ashipde)\
**Post date:** [June 27, 2022, 11:18pm UTC](https://discourse.slicer.org/t/lungctanalyzer-in-macos-missing-os-startfile/24058/4 "2022-06-27T23:18:09Z")

</div>

@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).

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [June 28, 2022, 8:34am UTC](https://discourse.slicer.org/t/lungctanalyzer-in-macos-missing-os-startfile/24058/5 "2022-06-28T08:34:54Z")

</div>

Thank you. I [removed the backslash generation](https://github.com/rbumm/SlicerLungCTAnalyzer/commit/9d7567e9f9a1a56905106f9bc2e29a1abb1166ea) in the PDF path for macOS and Linux.  
Could you test again?

---

<div class="post-metadata">

**Author:** ![ashipde](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ashipde/32/15695_2.png) [@ashipde](https://discourse.slicer.org/u/ashipde)\
**Post date:** [June 28, 2022, 9:42pm UTC](https://discourse.slicer.org/t/lungctanalyzer-in-macos-missing-os-startfile/24058/6 "2022-06-28T21:42:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 28, 2022, 11:30pm UTC](https://discourse.slicer.org/t/lungctanalyzer-in-macos-missing-os-startfile/24058/7 "2022-06-28T23:30:50Z")

</div>

@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](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#launch-external-process-in-startup-environment).

---

<div class="post-metadata">

**Author:** ![ashipde](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ashipde/32/15695_2.png) [@ashipde](https://discourse.slicer.org/u/ashipde)\
**Post date:** [June 29, 2022, 1:19am UTC](https://discourse.slicer.org/t/lungctanalyzer-in-macos-missing-os-startfile/24058/8 "2022-06-29T01:19:52Z")

</div>

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.
