Skip to content

Instantly share code, notes, and snippets.

@0x00b1
Last active July 29, 2016 23:56
Show Gist options
  • Select an option

  • Save 0x00b1/6a57a573dc8d4c6b694abfba2e85a7b1 to your computer and use it in GitHub Desktop.

Select an option

Save 0x00b1/6a57a573dc8d4c6b694abfba2e85a7b1 to your computer and use it in GitHub Desktop.

SimpleITK on OS X El Capitan with Homebrew Python

Unfortuantly, SimpleITK links your system Python rather than your Homebrew Python, i.e.

$ pip install SimpleITK

$ python
Python 2.7.12 (default, Jun 29 2016, 14:05:02) 
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import SimpleITK
Fatal Python error: PyThreadState_Get: no current thread
Abort trap: 6

It’s easily fixed with otool and install_name_tool:

$ pip install SimpleITK

$ otool -L /usr/local/lib/python2.7/site-packages/SimpleITK/_SimpleITK.so 
/usr/local/lib/python2.7/site-packages/SimpleITK/_SimpleITK.so:
	/System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.1)
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 635.19.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
	/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)

$ install_name_tool -change /System/Library/Frameworks/Python.framework/Versions/2.7/Python \
	/usr/local/Frameworks/Python.framework/Python \
	/usr/local/lib/python2.7/site-packages/SimpleITK/_SimpleITK.so
	
$ python
Python 2.7.12 (default, Jun 29 2016, 14:05:02) 
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import SimpleITK
>>> exit()

Enjoy!

@mcquin

mcquin commented Jul 29, 2016

Copy link
Copy Markdown

❤️ 💯 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment