import SimpleITK fails

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/”, line 14, in swig_import_helper
return importlib.import_module(mname)
File “/Users/mkvasnyt/anaconda3/lib/python3.6/importlib/”, 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/”, 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/”, 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/”, line 16, in swig_import_helper
return importlib.import_module(’_SimpleITK’)
File “/Users/mkvasnyt/anaconda3/lib/python3.6/importlib/”, 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,,,

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


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

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

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:

otool -L ~/.virtualenvs/sitk/lib/python2.7/site-packages/SimpleITK/ 
	/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)