In the situation using python on homebrew
$ brew install --python --qt vtk
Then
import vtk
# => Fatal Python error: PyThreadState_Get: no current thread. Abort trap: 6
Will be.
This is as mentioned in the homebrew-science issue OSX in * .dylib and * .so that comes down with brew install This is because the Python Path on the system side is embedded.
Try otool -L (Xcode Command Line Tools are required to use otool and install_name_tool)
$ otool -L /usr/local/Cellar/vtk/7.0.0_3/lib/libvtkCommonCorePython27D-7.0.dylib
/usr/local/Cellar/vtk/7.0.0_3/lib/libvtkCommonCorePython27D-7.0.dylib:
/usr/local/opt/vtk/lib/libvtkCommonCorePython27D-7.0.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/local/Cellar/vtk/7.0.0_3/lib/libvtkWrappingPython27Core-7.0.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/local/Cellar/vtk/7.0.0_3/lib/libvtkCommonCore-7.0.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.10)
/usr/local/Cellar/vtk/7.0.0_3/lib/libvtksys-7.0.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
As you can see, the link to /System/Library/Frameworks/Python.framework/Versions/2.7/Python is embedded. To fix this, use install_name_tool
$ sudo install_name_tool -change /System/Library/Frameworks/Python.framework/Versions/2.7/Python /usr/local/Cellar/python/2.7.11/Frameworks/Python /usr/local/Cellar/vtk/7.0.0_3/lib/libvtkCommonCorePython27D-7.0.dylib
Just run. (Sudo is required for rewriting) When I check it,
$ otool -L /usr/local/Cellar/vtk/7.0.0_3/lib/libvtkCommonCorePython27D-7.0.dylib
/usr/local/Cellar/vtk/7.0.0_3/lib/libvtkCommonCorePython27D-7.0.dylib:
/usr/local/opt/vtk/lib/libvtkCommonCorePython27D-7.0.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/local/Cellar/vtk/7.0.0_3/lib/libvtkWrappingPython27Core-7.0.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/local/Cellar/vtk/7.0.0_3/lib/libvtkCommonCore-7.0.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/local/Cellar/python/2.7.11/Frameworks/Python (compatibility version 2.7.0, current version 2.7.10)
/usr/local/Cellar/vtk/7.0.0_3/lib/libvtksys-7.0.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
You can see that the link can be modified to the path of brew python. Not this one needs to be changed, but __ / usr / local / lib / python2.7 / site-in addition to __ / usr / local / Cellar / vtk / {version} /lib/*.dylib__ Since packages / vtk / vtk * .so__ also needs to be modified, I wrote the following script.
vtk_fix_pythonpath.sh
#!/bin/sh
SystemPythonPath=/System/Library/Frameworks/Python.framework/Versions/2.7/Python #Change according to the version of python you are using
BrewPythonPath=/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Python #Change according to the version of python you are using
function replace_system_python() {
echo " -- before -- "
otool -L $1
install_name_tool -change ${SystemPythonPath} ${BrewPythonPath} $1
echo " -- after -- "
otool -L $1
}
for file in `find /usr/local/lib/python2.7/site-packages/vtk/vtk*.so`;do
replace_system_python ${file}
done
for file in `find /usr/local/Cellar/vtk/7.0.0_3/lib/*.dylib`;do
replace_system_python ${file}
done
It's bad manners to run install_name_tool -change on all dylib, so files (even those that don't include the Python path), but it shouldn't be a problem as it won't be replaced unless it matches.
$ sudo ./vtk_fix_pythonpath.sh
After that, if you check if you can import,
import vtk
# => No error!!!!!!
I was able to import without problems. If you read the home-science issue, it seems that some people have written a patch that can build vtk without embedding links, but do you still want to fix the main body side?
Recommended Posts