# SimpleITK import error

**URL:** <https://discourse.slicer.org/t/simpleitk-import-error/7294>\
**Category:** Support\
**Created:** [June 24, 2019, 3:31pm UTC](https://discourse.slicer.org/t/simpleitk-import-error/7294 "2019-06-24T15:31:00Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [June 30, 2019, 5:47pm UTC](https://discourse.slicer.org/t/simpleitk-import-error/7294/21 "2019-06-30T17:47:10Z")

</div>

This should now be fixed in [r28350](http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&revision=28350)

In a nutshell, regular expression can not be used as globbing expression.

---

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [July 1, 2019, 2:49pm UTC](https://discourse.slicer.org/t/simpleitk-import-error/7294/22 "2019-07-01T14:49:47Z")

</div>

> [@jcfr](#):
>
> This should now be fixed in [r28350](http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&revision=28350)

It is, thanks @jcfr!

---

<div class="post-metadata">

**Author:** ![HodaGH](https://avatars.discourse-cdn.com/v4/letter/h/858c86/32.png) [@HodaGH](https://discourse.slicer.org/u/HodaGH)\
**Post date:** [March 1, 2021, 8:44pm UTC](https://discourse.slicer.org/t/simpleitk-import-error/7294/23 "2021-03-01T20:44:39Z")

</div>

Hi,

I’m trying to use SimpleElastix within Anaconda while using Slicer (to do my registration). I feel like my problem is related to this issue here.

So it seems that SimpleElastix is not included in the SimpleITK of Slicer because when I import SimpleITK as sitk I get this error:

```auto
Module 'SimpleITK' has no attribute 'ElastixImageFilter'

```

How can I tell anaconda which version to use?

Similar to the solution here I changed `_SimpleITK.so` to `_SimpleITK*.so` in my build directory for SimpleElastix installation and then did sudo python setup.py install again but it still looks for `_SimpleITK.so`.

Do you have any recommendations?

Thanks very much.

---

<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:** [March 1, 2021, 9:08pm UTC](https://discourse.slicer.org/t/simpleitk-import-error/7294/24 "2021-03-01T21:08:06Z")

</div>

You can use [SlicerElastix](https://github.com/lassoan/SlicerElastix) extension and to get Elastix binaries that are compatible with Slicer’s SimpleITK version that you can use from Python. Command-line interface may not be as convenient as Python, but it comes with nice perks, such as being able to run the registration in the background and stop it any time without impacting the application.

---

<div class="post-metadata">

**Author:** ![HodaGH](https://avatars.discourse-cdn.com/v4/letter/h/858c86/32.png) [@HodaGH](https://discourse.slicer.org/u/HodaGH)\
**Post date:** [March 2, 2021, 1:46am UTC](https://discourse.slicer.org/t/simpleitk-import-error/7294/25 "2021-03-02T01:46:09Z")

</div>

Sorry I’m a beginner so I have the SlicerElastix installed on my computer but should I import something? (I tried importing SlicerElastix but didn’t work)  
I also tried slicer.util.pip\_install(‘SimpleElastix’) but this is the error I get (my computer is mac 10.14):

ERROR: Could not find a version that satisfies the requirement SimpleElastix (from versions: 0.9.1.macosx-10.11-intel, 0.10.0.post224.macosx-10.6-x86\_64)  
ERROR: No matching distribution found for SimpleElastix

when I write my code in the jupyter notebook I import SimpleITK as sitk. Here’s the code:

```python
import SimpleITK as sitk

# Concatenate the ND images into one (N+1)D image
MRI_nodes = ['image1.hdr', ..., 'imageN.hdr']
vectorOfImages = sitk.VectorOfImage()

for volumenode in MRI_nodes:
    sitk_images = sitkUtils.PullVolumeFromSlicer(volumenode)
    vectorOfImages.push_back(sitk_images)
image = sitk.JoinSeries(vectorOfImages)
# Register
elastixImageFilter = sitk.ElastixImageFilter() 
elastixImageFilter.SetFixedImage(image)
elastixImageFilter.SetMovingImage(image)
elastixImageFilter.SetParameterMap(sitk.GetDefaultParameterMap('groupwise'))
elastixImageFilter.Execute()

```

\*\*elastixImageFilter = sitk.ElastixImageFilter() → this is what gives me the error and when I use the tab after sitk. I don’t see ElastixImageFilter in the menu

---

<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:** [March 2, 2021, 4:59am UTC](https://discourse.slicer.org/t/simpleitk-import-error/7294/26 "2021-03-02T04:59:59Z")

</div>

> [@HodaGH](#):
>
> Sorry I’m a beginner so I have the SlicerElastix installed on my computer but should I import something? (I tried importing SlicerElastix but didn’t work)

[Sequence registration module](https://github.com/moselhy/SlicerSequenceRegistration/blob/master/SequenceRegistration/SequenceRegistration.py) is a good example of how to run the Elastix command-line executables from Python. These executables are not Python modules, they are command-line applications.

> [@HodaGH](#):
>
> ERROR: Could not find a version that satisfies the requirement SimpleElastix

See above. SlicerElastix extension provides you Elastix command-line applications, not the Python package.

If you absolutely want to run Elastix via SimpleElastix then you may need to do it in an external Python environment. For example, you install anaconda, create a virtual Python environment, in that environment you install SimpleElastix, and then from Slicer you run the registration script in that environment.

[Previous page](https://discourse.slicer.org/t/simpleitk-import-error/7294.md?page=1)
