# 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:** 20\
**Page:** 1

<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:** [June 24, 2019, 3:31pm UTC](https://discourse.slicer.org/t/simpleitk-import-error/7294/1 "2019-06-24T15:31:00Z")

</div>

Hi all,

I’ve been getting this error for a while on mac. This is from the latest nightly. Please let me know if you’d like me to report it on the issue tracker.

```auto
Python 3.6.7 (default, Jun 23 2019, 23:06:42) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
>>> import SimpleITK
Traceback (most recent call last):
  File "/Applications/Slicer.app/Contents/lib/Python/lib/python3.6/site-packages/SimpleITK/SimpleITK.py", line 18, in swig_import_helper
    return importlib.import_module(mname)
  File "/Applications/Slicer.app/Contents/lib/Python/lib/python3.6/importlib/ __init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 658, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 571, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 922, in create_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: dlopen(/Applications/Slicer.app/Contents/lib/Python/lib/python3.6/site-packages/SimpleITK/_SimpleITK.cpython-36m-darwin.so, 1): Library not loaded: /Volumes/Dashboards/Preview/Slicer-0-build/ITK-build/lib/libITKIOBruker-5.0.1.dylib
  Referenced from: /Applications/Slicer.app/Contents/lib/Python/lib/python3.6/site-packages/SimpleITK/_SimpleITK.cpython-36m-darwin.so
  Reason: image not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Applications/Slicer.app/Contents/lib/Python/lib/python3.6/site-packages/SimpleITK/ __init__.py", line 1, in <module>
    from .SimpleITK import *
  File "/Applications/Slicer.app/Contents/lib/Python/lib/python3.6/site-packages/SimpleITK/SimpleITK.py", line 21, in <module>
    _SimpleITK = swig_import_helper()
  File "/Applications/Slicer.app/Contents/lib/Python/lib/python3.6/site-packages/SimpleITK/SimpleITK.py", line 20, in swig_import_helper
    return importlib.import_module('_SimpleITK')
  File "/Applications/Slicer.app/Contents/lib/Python/lib/python3.6/importlib/ __init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_SimpleITK'
>>> 

```

---

<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 25, 2019, 10:44pm UTC](https://discourse.slicer.org/t/simpleitk-import-error/7294/2 "2019-06-25T22:44:23Z")

</div>

Hi @Fernando -

I can replicate your issue on mac with the nightly. The key message seems to be missing `libITKIOBruker-5.0.1.dylib`.

@blowekamp is coming to project week and hopefully we can look through this together. It seems it’s something to do with the way SimpleITK interacts with remote ITK modules with image IO functions.

---

<div class="post-metadata">

**Author:** ![blowekamp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/blowekamp/32/1386_2.png) [@blowekamp](https://discourse.slicer.org/u/blowekamp)\
**Post date:** [June 26, 2019, 12:40pm UTC](https://discourse.slicer.org/t/simpleitk-import-error/7294/3 "2019-06-26T12:40:53Z")

</div>

> [@pieper](#):
>
> I can replicate your issue on mac with the nightly. The key message seems to be missing `libITKIOBruker-5.0.1.dylib` .

This indicate that when when the SimpleITK library is being loaded the linker can not find the `libITKIOBruker-5.0.1.dylib` dependency. The things to check are:

- Does `libITKIOBruker-5.0.1.dylib` exist in the proper place in the Mac Bundle?
- Run `otool -L` on `_SimpleITK.so` to verify that it has been fixed up correctly.

Unfortunately, I seem to be having trouble getting to [www.slicer.org](http://www.slicer.org) right now to download the latest nightly. I’ll be at project week on Thursday.

---

<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 26, 2019, 2:20pm UTC](https://discourse.slicer.org/t/simpleitk-import-error/7294/4 "2019-06-26T14:20:27Z")

</div>

Thanks @blowekamp - [slicer.org](http://slicer.org) seems to be working now for me if you want to have a look.

When we looked before it seems the Bruker reader is not being included or fixed up, maybe as part of the SimpleITK build step. Do you know if that’s something that’s changed recently? It works in Slicer 4.10.2 but that’s an older ITK. We can look at it when you are at Project Week.

---

<div class="post-metadata">

**Author:** ![blowekamp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/blowekamp/32/1386_2.png) [@blowekamp](https://discourse.slicer.org/u/blowekamp)\
**Post date:** [June 26, 2019, 3:14pm UTC](https://discourse.slicer.org/t/simpleitk-import-error/7294/5 "2019-06-26T15:14:57Z")

</div>

I was able to download both the nightly and the release versions.

The suffix on the SimpleITK library has changed a bit:

```auto
$ find Slicer-4.1* -name _SimpleITK\*
Slicer-4.10.2.app/Contents/lib/Python/lib/python2.7/site-packages/SimpleITK/_SimpleITK.so
Slicer-4.11.0-2019-06-24.app/Contents/lib/Python/lib/python3.6/site-packages/SimpleITK/_SimpleITK.cpython-36m-darwin.so

```

And the SimpleITK library is not being fixed up at all:

```auto
 $otool -L Slicer-4.11.0-2019-06-24.app/Contents/lib/Python/lib/python3.6/site-packages/SimpleITK/_SimpleITK.cpython-36m-darwin.so

Slicer-4.11.0-2019-06-24.app/Contents/lib/Python/lib/python3.6/site-packages/SimpleITK/_SimpleITK.cpython-36m-darwin.so:
	/Volumes/Dashboards/Preview/Slicer-0-build/ITK-build/lib/libITKIOBruker-5.0.1.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Volumes/Dashboards/Preview/Slicer-0-build/ITK-build/lib/libITKIODCMTK-5.0.1.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Volumes/Dashboards/Preview/Slicer-0-build/ITK-build/lib/libITKIOHDF5-5.0.1.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Volumes/Dashboards/Preview/Slicer-0-build/ITK-build/lib/libITKIOJPEG2000-5.0.1.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Volumes/Dashboards/Preview/Slicer-0-build/ITK-build/lib/libITKIOLSM-5.0.1.dylib (compatibility version 1.0.0, current version 1.0.0)

```

---

<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 26, 2019, 3:31pm UTC](https://discourse.slicer.org/t/simpleitk-import-error/7294/6 "2019-06-26T15:31:09Z")

</div>

Ah - I guess it’s a python3 related change?

---

<div class="post-metadata">

**Author:** ![blowekamp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/blowekamp/32/1386_2.png) [@blowekamp](https://discourse.slicer.org/u/blowekamp)\
**Post date:** [June 26, 2019, 3:34pm UTC](https://discourse.slicer.org/t/simpleitk-import-error/7294/7 "2019-06-26T15:34:53Z")

</div>

Here is a PR which should fix it:

> <https://github.com/Slicer/Slicer/pull/1160>

I don’t have a Mac setup for Slicer development, so I could test it. This certainly looks like the cause of the SimpleITK library not being fixed up.

---

<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 27, 2019, 6:15am UTC](https://discourse.slicer.org/t/simpleitk-import-error/7294/8 "2019-06-27T06:15:02Z")

</div>

Thanks @blowekamp for the fix 🙏

It has been integrated in [r28347](http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&revision=28347)

---

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [June 28, 2019, 11:32am UTC](https://discourse.slicer.org/t/simpleitk-import-error/7294/9 "2019-06-28T11:32:33Z")

</div>

Unfortunately, the problem persists in today’s nightly.

---

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [June 28, 2019, 6:28pm UTC](https://discourse.slicer.org/t/simpleitk-import-error/7294/10 "2019-06-28T18:28:34Z")

</div>

This PR from @blowekamp should hopefully fix the problem in the next nightly: [https://github.com/Slicer/Slicer/pull/1161](https://github.com/Slicer/Slicer/pull/1161).

Meanwhile, @jcfr had the idea to install SimpleITK using pip. I first removed the SimpleITK local package:

```bash
$ rm -rf ./lib/Python/lib/python3.6/site-packages/SimpleITK*

```

And then did `slicer.util.pip_install("SimpleITK")`, but after restarting Slicer, I got a crash, [here’s the stack trace](https://gist.github.com/fedorov/9eb533309770c61cd6d612104c20c64b).

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [June 28, 2019, 7:23pm UTC](https://discourse.slicer.org/t/simpleitk-import-error/7294/11 "2019-06-28T19:23:13Z")

</div>

I think SimpleITK from pip install is v1.2.0 which is built using ITK v4.13 even though it is ITKv5 compatible. Probably not the best since Slicer is using ITKv5

Check with

```python
import SimpleITK as sitk
sitk.Version().ITKVersionString()

```

---

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [June 28, 2019, 7:29pm UTC](https://discourse.slicer.org/t/simpleitk-import-error/7294/12 "2019-06-28T19:29:00Z")

</div>

Yes, indeed SimpleITK from pip is 4.13.

I thought I asked a question along those lines to JC at the project week, and I thought the response was that packages installed via pip are installed into separate directory, along with their dependencies, so they would not conflict with any packages already installed. I guess I misunderstood the answer. I thought SimpleITK will use ITK it will bring along, and will not conflict with Slicer ITK 5.

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [June 28, 2019, 7:36pm UTC](https://discourse.slicer.org/t/simpleitk-import-error/7294/13 "2019-06-28T19:36:49Z")

</div>

I did the following using SlicerPython directly instead of within Slicer and didn’t have any crashing on open.

```auto
./SlicerPython.exe -m pip uninstall SimpleITK
Uninstalling SimpleITK-1.2.0rc2.dev413:
  Would remove:
    c:\users\jamesbutler\appdata\local\na-mic\slicer 4.11.0-2019-06-23\lib\python\lib\site-packages\simpleitk
    c:\users\jamesbutler\appdata\local\na-mic\slicer 4.11.0-2019-06-23\lib\python\lib\site-packages\simpleitk-1.2.0rc2.dev413-py3.6.egg-info
Proceed (y / n)? 
  Successfully uninstalled SimpleITK-1.2.0rc2.dev413
./SlicerPython.exe -m pip install SimpleITK
Collecting SimpleITK
  Using cached https://files.pythonhosted.org/packages/ff/b3/2c79f38d113eb3912703261979c88ec1f640488d6d9fac391de42052e8cb/SimpleITK-1.2.0-cp36-cp36m-win_amd64.whl
Installing collected packages: SimpleITK
Successfully installed SimpleITK-1.2.0

```

There was this warning on open though.

```auto
WARNING: In C:\d\VS14-Win64-pkg\SimpleITK-build\ITK\Modules\Core\Common\src\itkObjectFactoryBase.cxx, line 664
Possible incompatible factory load:
Running itk version :
itk version 4.13.1
Loaded factory version:
itk version 5.0.0
Loading factory:
C:/Users/JamesButler/AppData/Local/NA-MIC/Slicer 4.11.0-2019-06-23/bin/../lib/Slicer-4.11/ITKFactories\MRMLIDIOPlugin.dll

```

---

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [June 28, 2019, 7:40pm UTC](https://discourse.slicer.org/t/simpleitk-import-error/7294/14 "2019-06-28T19:40:49Z")

</div>

What happens when you do `import SimpleITK` in the Slicer python console? I get a crash.

It is also interesting that somehow I am not getting the warning that you mentioned…

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [June 28, 2019, 7:48pm UTC](https://discourse.slicer.org/t/simpleitk-import-error/7294/15 "2019-06-28T19:48:36Z")

</div>

I get the output warning (separate window) after importing SimpleITK. Here’s the output I get. No crashing.

```auto
>>> import SimpleITK as sitk
>>> sitk.Version().VersionString()
'1.2.0'
>>> sitk.Version().ITKVersionString()
'4.13'

```

---

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [June 28, 2019, 7:52pm UTC](https://discourse.slicer.org/t/simpleitk-import-error/7294/16 "2019-06-28T19:52:35Z")

</div>

Hmmm… I am on Mac, and installed from this nightly package: Slicer-4.11.0-2019-06-27-macosx-amd64. Is this what you have?

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [June 28, 2019, 8:11pm UTC](https://discourse.slicer.org/t/simpleitk-import-error/7294/17 "2019-06-28T20:11:32Z")

</div>

I’m on Windows. I tried again with Slicer-4.11.0-2019-06-27-win-amd64 and didn’t have issues.

---

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [June 28, 2019, 8:13pm UTC](https://discourse.slicer.org/t/simpleitk-import-error/7294/18 "2019-06-28T20:13:52Z")

</div>

@jamesobutler thanks a lot for your efforts, I appreciate it!

I will wait for the nightly package, hopefully it works tomorrow.

---

<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, 2019, 10:33pm UTC](https://discourse.slicer.org/t/simpleitk-import-error/7294/19 "2019-06-28T22:33:23Z")

</div>

As I understood from @jcfr, ITK Puthon is built statically, so there is no version conflict except the IO factory. Unfortunately, ABI incompatibility in the IO factory can break everything.

I guess SimpleITK will upgrade to the latest stable ITK version (5.x) at some point, which may happen more quickly if we ask for it.

---

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [June 30, 2019, 2:49pm UTC](https://discourse.slicer.org/t/simpleitk-import-error/7294/20 "2019-06-30T14:49:19Z")

</div>

Unfortunately, as of r28349 the problem is still there.

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