# import SimpleITK fails

**URL:** https://discourse.itk.org/t/import-simpleitk-fails/1009
**Category:** Beginner Questions
**Created:** [June 15, 2018, 12:52pm UTC](https://discourse.itk.org/t/import-simpleitk-fails/1009 "2018-06-15T12:52:40Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mkvasnyt](https://discourse.itk.org/letter_avatar_proxy/v4/letter/m/5daacb/32.png) [@mkvasnyt](https://discourse.itk.org/u/mkvasnyt)
#### Post date: [June 15, 2018, 12:52pm UTC](https://discourse.itk.org/t/import-simpleitk-fails/1009/1 "2018-06-15T12:52:41Z")

</div>

Dear all,  
I’ve built and tested custom version of SimpleITK on MacOS Sierra 10.12.5. 99% of tests passed, from Python tests only 2 failed.  
I also see that newly built SimpleITK package is successfully installed to root environment in Anaconda.  
Nevertheless, when I attempt to import SimpleITK I receive a following error message:

import SimpleITK  
Traceback (most recent call last):  
File “/Users/mkvasnyt/anaconda3/lib/python3.6/site-packages/SimpleITK-1.2.0.dev72+g7d893-py3.6-macosx-10.7-x86\_64.egg/SimpleITK/SimpleITK.py”, line 14, in swig\_import\_helper  
return importlib.import\_module(mname)  
File “/Users/mkvasnyt/anaconda3/lib/python3.6/importlib/ **init**.py”, line 126, in import\_module  
return \_bootstrap.\_gcd\_import(name[level:], package, level)  
File “”, line 994, in \_gcd\_import  
File “”, line 971, in \_find\_and\_load  
File “”, line 955, in \_find\_and\_load\_unlocked  
File “”, line 658, in \_load\_unlocked  
File “”, line 571, in module\_from\_spec  
File “”, line 922, in create\_module  
File “”, line 219, in \_call\_with\_frames\_removed  
ImportError: dynamic module does not define module export function (PyInit\_\_SimpleITK)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):  
File “”, line 1, in   
File “/Users/mkvasnyt/anaconda3/lib/python3.6/site-packages/SimpleITK-1.2.0.dev72+g7d893-py3.6-macosx-10.7-x86\_64.egg/SimpleITK/ **init**.py”, line 1, in   
from .SimpleITK import \*  
File “/Users/mkvasnyt/anaconda3/lib/python3.6/site-packages/SimpleITK-1.2.0.dev72+g7d893-py3.6-macosx-10.7-x86\_64.egg/SimpleITK/SimpleITK.py”, line 17, in   
\_SimpleITK = swig\_import\_helper()  
File “/Users/mkvasnyt/anaconda3/lib/python3.6/site-packages/SimpleITK-1.2.0.dev72+g7d893-py3.6-macosx-10.7-x86\_64.egg/SimpleITK/SimpleITK.py”, line 16, in swig\_import\_helper  
return importlib.import\_module(’\_SimpleITK’)  
File “/Users/mkvasnyt/anaconda3/lib/python3.6/importlib/ **init**.py”, line 126, in import\_module  
return \_bootstrap.\_gcd\_import(name[level:], package, level)  
ModuleNotFoundError: No module named ‘\_SimpleITK’

The SimpleITK subfolder of SimpleITK-1.2.0.dev72+g7d893-py3.6-macosx-10.7-x86\_64.egg contains **init**.py, SimpleITK.py, \_SimpleITK.py, \_SimpleITK.cpython-36m-darwin.so.

Could you please hint me what shall I do to enable import?  
Thanks!

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [June 15, 2018, 12:59pm UTC](https://discourse.itk.org/t/import-simpleitk-fails/1009/2 "2018-06-15T12:59:41Z")

</div>

> [@mkvasnyt](#):
>
> evertheless, when I attempt to import SimpleITK I receive a following error message:

Hello,

How did you configure SimpleITK? What CMake options did you change? Did you enable shared libraries?

---

<div class="post-metadata">

### Author: ![mkvasnyt](https://discourse.itk.org/letter_avatar_proxy/v4/letter/m/5daacb/32.png) [@mkvasnyt](https://discourse.itk.org/u/mkvasnyt)
#### Post date: [June 15, 2018, 1:17pm UTC](https://discourse.itk.org/t/import-simpleitk-fails/1009/3 "2018-06-15T13:17:03Z")

</div>

I used SuperBuild configuration with the only change to SimpleITK\_USE\_SYSTEM\_ITK = On and correspondingly specified the ITK\_DIR. I did not explicitly change the rest of the settings.

When I look at CMake configuration now though I notice that PYTHON\_EXECUTABLE=/usr/bin/python,  
PYTHON\_LIBRARY=/usr/lib/libpython2.7.dylib. If I understand correctly, it should have pointed to Anaconda’s python and .dylib. Could it be the cause of a problem?

Update: tested installation and import on system python (/usr/bin/python). It works. So my bad … Shall rebuild with correct CMake configuration

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [June 15, 2018, 1:29pm UTC](https://discourse.itk.org/t/import-simpleitk-fails/1009/4 "2018-06-15T13:29:31Z")

</div>

> [@mkvasnyt](#):
>
> When I look at CMake configuration now though I notice that PYTHON\_EXECUTABLE=/usr/bin/python,  
> PYTHON\_LIBRARY=/usr/lib/libpython2.7.dylib. If I understand correctly, it should have pointed to Anaconda’s python and .dylib. Could it be the cause of a problem?

Yes, that is certainly a problem. Compiling against py2.7 and using python 3.4 will not work.

You can also further inspect the library with the `otool` command. This will indicate the library dependencies, such and if ITK was compiled with shared libraries:

```auto
otool -L ~/.virtualenvs/sitk/lib/python2.7/site-packages/SimpleITK/_SimpleITK.so 
/Users/blowekamp/.virtualenvs/sitk/lib/python2.7/site-packages/SimpleITK/_SimpleITK.so:
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
	/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 104.1.0)

```
