# AI segmentation with lung CT analyzer error

**URL:** <https://discourse.slicer.org/t/ai-segmentation-with-lung-ct-analyzer-error/25678>\
**Category:** Support\
**Tags:** segmentation, python, lungctanalyzer\
**Created:** [October 13, 2022, 11:44am UTC](https://discourse.slicer.org/t/ai-segmentation-with-lung-ct-analyzer-error/25678 "2022-10-13T11:44:10Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![MMdeB](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mmdeb/32/16912_2.png) [@MMdeB](https://discourse.slicer.org/u/MMdeB)\
**Post date:** [October 13, 2022, 11:44am UTC](https://discourse.slicer.org/t/ai-segmentation-with-lung-ct-analyzer-error/25678/1 "2022-10-13T11:44:10Z")

</div>

Hi, I’ve been trying to use the Lung CT Analyzer extension with the AI segmentation ‘lung mask’, but I cannot get it to work. First, an error occurred that ‘torch was not present’, but I solved this by installing PyTorch extension in slicer (and then install pytorch via this module). However, afterwards I still get an error when I try to segment the lung.

First, when I press apply, I get a warning:

> pytorch CUDA is not found on your system. The AI processing will last 3-10 minutes. Do you want to continue?

If I press OK, I will get the following error:

> Failed to compute results: Command ‘[‘C:/Users/mmdeboer/AppData/Local/NA-MIC/Slicer 5.0.3/bin/…/bin\PythonSlicer.EXE’, ‘-m’, ‘pip’, ‘install’, ‘git+https://github.com/JoHof/lungmask’]’ returned non-zero exit status 1.

What do I have to do to solve this error? Thanks in advance!

---

<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:** [October 13, 2022, 11:59am UTC](https://discourse.slicer.org/t/ai-segmentation-with-lung-ct-analyzer-error/25678/2 "2022-10-13T11:59:09Z")

</div>

> [@MMdeB](#):
>
> First, when I press apply, I get a warning:
> 
> > pytorch CUDA is not found on your system. The AI processing will last 3-10 minutes. Do you want to continue?

What GPU do you have in use?  
Message 1 is normal if you have no GPU or a GPU that does not support CUDA. CUDA needs an Nvidia GPU.

> [@MMdeB](#):
>
> If I press OK, I will get the following error:
> 
> > Failed to compute results: Command ‘[‘C:/Users/mmdeboer/AppData/Local/NA-MIC/Slicer 5.0.3/bin/…/bin\PythonSlicer.EXE’, ‘-m’, ‘pip’, ‘install’, ‘git+https://github.com/JoHof/lungmask’]’ returned non-zero exit status 1.
> 
> What do I have to do to solve this error? Thanks in advance!

This is strange.  
Could you restart Slicer and paste

```auto
slicer.util.pip_install("git+https://github.com/JoHof/lungmask")

```

into the Python Interactor, press return, and post the result?  
Thank you.

---

<div class="post-metadata">

**Author:** ![Filipe\_Pagaimo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/filipe_pagaimo/32/4385_2.png) [@Filipe\_Pagaimo](https://discourse.slicer.org/u/Filipe_Pagaimo)\
**Post date:** [February 15, 2023, 12:30am UTC](https://discourse.slicer.org/t/ai-segmentation-with-lung-ct-analyzer-error/25678/3 "2023-02-15T00:30:44Z")

</div>

Hi, I am facing a similar problem. My laptop has a NVDIA GeForce RTX 3050 Ti.

When pasting the suggested line on the Python console:

> slicer.util.pip\_install(“git+https://github.com/JoHof/lungmask”)

I get the message:

> Collecting git+https://github.com/JoHof/lungmask  
> Cloning [GitHub - JoHof/lungmask: Automated lung segmentation in CT](https://github.com/JoHof/lungmask) to c:\users\pagai\appdata\local\temp\pip-req-build-y\_ut0tcq  
> ERROR: Error [WinError 2] The system cannot find the file specified while executing command git version  
> ERROR: Cannot find command ‘git’ - do you have ‘git’ installed and in your PATH?
> 
> [notice] A new release of pip available: 22.3 → 23.0  
> [notice] To update, run: python-real.exe -m pip install --upgrade pip

Thank you

---

<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:** [February 15, 2023, 5:10am UTC](https://discourse.slicer.org/t/ai-segmentation-with-lung-ct-analyzer-error/25678/4 "2023-02-15T05:10:19Z")

</div>

> [@rbumm](#):
>
> `slicer.util.pip_install("git+https://github.com/JoHof/lungmask")`

@rbumm It is important to note that users don’t have git installed on their system. You can install git relatively easily on Windows (see complete implementation [here](https://github.com/lassoan/SlicerTotalSegmentator/commit/5cc78d783b64fda32d32a2b96d4499b0d2533863)), but I don’t think there is no easy/standard solution that works on all linux and macOS configurations. It is easier to install from the zip file that github provides (as shown [here](https://github.com/lassoan/SlicerTotalSegmentator/commit/1eb9aa7df8f07fac6f080ea4c6f59b6ccd4d75a6#diff-25cf74003570e77f7e900eb7a84476163d86e68f055332dbca69ed0293f03a92R519)) because then you don’t need git at all.

Note that the disadvantage of using git+https or git .zip format is that if the URL does not change (e.g., because you use the latest main version) then pip will just use the latest cached version. Therefore, instead of using a branch name, I would recommend to use a specific git hash, as it is done [here](https://github.com/lassoan/SlicerTotalSegmentator/commit/d9b4f6e7a2eae05d099836aa8d314a59df066262#diff-25cf74003570e77f7e900eb7a84476163d86e68f055332dbca69ed0293f03a92R301).

All these issues are solved if the maintainer uploads a package to PyPI. If the maintainer of this package does not do it then you may enter an issue in the repository’s bugtracker to request this.

---

<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:** [February 15, 2023, 8:23am UTC](https://discourse.slicer.org/t/ai-segmentation-with-lung-ct-analyzer-error/25678/5 "2023-02-15T08:23:28Z")

</div>

Thank you @lassoan, very helpful.

> [@lassoan](#):
>
> All these issues are solved if the maintainer uploads a package to PyPI. If the maintainer of this package does not do it then you may enter an issue in the repository’s bug tracker to request this.

How are these issues solved then? Will ` slicer.util.pip_install()` recognize the latest version?

Sidenote: `slicer.util.pip_uninstall()` only works in 5.2.1 if you do a `slicer.util.restart()` afterward.

---

<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:** [February 15, 2023, 3:05pm UTC](https://discourse.slicer.org/t/ai-segmentation-with-lung-ct-analyzer-error/25678/6 "2023-02-15T15:05:13Z")

</div>

> [@rbumm](#):
>
> How are these issues solved then? Will ` slicer.util.pip_install()` recognize the latest version?

pip handles download, install, versioning, resolving version requirements, etc. `pip_install` will install the package according to the requirements that you specify. If you don’t specify any requirement then it just makes sure that some version of the package is installed. If you specify `--upgrade` then it’ll install the latest one. If you specify a version range then it’ll choose a version in that range.

> [@rbumm](#):
>
> Sidenote: `slicer.util.pip_uninstall()` only works in 5.2.1 if you do a `slicer.util.restart()` afterward.

Yes, if a Python package is already loaded then installing a new version will not change anything, as the Python scripts from the previous version are already loaded.

Note that `pip_uninstall` may fail if the Python package is in use and it contains shared libraries (DLLs). If you want to make uninstallation work, you would need to quit Slicer and run `PythonSlicer -m pip uninstall ...`, but often uninstalling while Slicer is running and then restarting is enough (and it is much easier to do than running some Python scripts outside Slicer). If Python package uninstallation was commonly needed then we could implement some mechanism to do it at Slicer application startup (before initializing Python, by launching the external PythonSlicer interpreter).

---

<div class="post-metadata">

**Author:** ![Johan\_Diaz\_Tovar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/johan_diaz_tovar/32/68654_2.png) [@Johan\_Diaz\_Tovar](https://discourse.slicer.org/u/Johan_Diaz_Tovar)\
**Post date:** [December 9, 2023, 9:23am UTC](https://discourse.slicer.org/t/ai-segmentation-with-lung-ct-analyzer-error/25678/7 "2023-12-09T09:23:06Z")

</div>

Hello everyone, I recently updated 3D slicer to the version 5.60 and when I’m trying to use the Lung CT Segmenter extension (which it was working before) I’m getting this error:

Failed to compute results: module ‘torch.backends’ has no attribute ‘mps’

I already checked the updates for PyTorch and the lungmask library, I even installed the version where it was working before (5.40) but even doing that it is not working and giving me the same error, what do you thinkg I can do…

I’m using 3D slicer in a Mac

---

<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:** [December 9, 2023, 6:01pm UTC](https://discourse.slicer.org/t/ai-segmentation-with-lung-ct-analyzer-error/25678/8 "2023-12-09T18:01:48Z")

</div>

Please report this error on the [lungmask GitHub](https://github.com/JoHof/lungmask) under issues. Can not reproduce that on a PC. The last version of lungmask obviously “adds support for mps (apple metal)”. If the problem can not be solved by the developer we will switch to an earlier version of lungmask.

---

<div class="post-metadata">

**Author:** ![Johan\_Diaz\_Tovar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/johan_diaz_tovar/32/68654_2.png) [@Johan\_Diaz\_Tovar](https://discourse.slicer.org/u/Johan_Diaz_Tovar)\
**Post date:** [December 10, 2023, 7:59pm UTC](https://discourse.slicer.org/t/ai-segmentation-with-lung-ct-analyzer-error/25678/9 "2023-12-10T19:59:47Z")

</div>

I reported there, thanks!

The version of Lungmask currently being used in my 3D slicer is the 0.2.18

---

<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:** [December 11, 2023, 10:03am UTC](https://discourse.slicer.org/t/ai-segmentation-with-lung-ct-analyzer-error/25678/10 "2023-12-11T10:03:43Z")

</div>

Can you try to use the Pytorch extension and install Pytorch in CPU mode ? Do you still get the error then ?

---

<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:** [December 11, 2023, 4:52pm UTC](https://discourse.slicer.org/t/ai-segmentation-with-lung-ct-analyzer-error/25678/11 "2023-12-11T16:52:46Z")

</div>

You could always install an earlier version of lungmask from the Python console:

```auto
slicer.util.pip_uninstall("lungmask")
slicer.util.pip_install("https://github.com/JoHof/lungmask/archive/18cfc8967501dc84c844d17594b711c0a8e4711b.zip")
# restart slicer

```

This will install lungmask 0.2.17

---

<div class="post-metadata">

**Author:** ![Johan\_Diaz\_Tovar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/johan_diaz_tovar/32/68654_2.png) [@Johan\_Diaz\_Tovar](https://discourse.slicer.org/u/Johan_Diaz_Tovar)\
**Post date:** [December 11, 2023, 6:47pm UTC](https://discourse.slicer.org/t/ai-segmentation-with-lung-ct-analyzer-error/25678/12 "2023-12-11T18:47:15Z")

</div>

Yes, I tried this before, it was set as automatic, I used the CPU mode same error

---

<div class="post-metadata">

**Author:** ![Johan\_Diaz\_Tovar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/johan_diaz_tovar/32/68654_2.png) [@Johan\_Diaz\_Tovar](https://discourse.slicer.org/u/Johan_Diaz_Tovar)\
**Post date:** [December 11, 2023, 7:02pm UTC](https://discourse.slicer.org/t/ai-segmentation-with-lung-ct-analyzer-error/25678/13 "2023-12-11T19:02:42Z")

</div>

Thank you so much!  
It defenitly solved the error, going back to the last version works

---

<div class="post-metadata">

**Author:** ![Daniel\_Lo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/daniel_lo/32/77935_2.png) [@Daniel\_Lo](https://discourse.slicer.org/u/Daniel_Lo)\
**Post date:** [September 25, 2024, 5:29am UTC](https://discourse.slicer.org/t/ai-segmentation-with-lung-ct-analyzer-error/25678/14 "2024-09-25T05:29:06Z")

</div>

![Screenshot 2024-09-25 at 13.28.21](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/c/6c8e84c821206408d0cdb5478685b3141c69d962.jpeg)this happened when i used AI segmentation for Lung CT segmenter
