Switch python version in MAC-OS is a confused problem, so i use pyenv to switch python version, it works very well:
vinllen@ ~$ python --version
Python 2.7.11
vinllen@ ~$ pyenv global <tab>
--help 2.7.10 3.4.0 system
vinllen@ ~$ pyenv global 3.4.0
--help 2.7.10 3.4.0 system
vinllen@ ~$ python --version
Python 3.4.0
Problem occurs when i using cmake
to compile a software called SimpleElastix, the error shows that my python version is unsuitable:
CMake Error at /usr/local/Cellar/cmake/3.3.1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find PythonLibs: Found unsuitable version "2.7.6", but required
is exact version "2.7.11" (found /usr/lib/libpython2.7.dylib)
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.3.1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:386 (_FPHSA_FAILURE_MESSAGE)
/usr/local/Cellar/cmake/3.3.1/share/cmake/Modules/FindPythonLibs.cmake:205 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
/Users/vinllen/opt/elastix/SimpleElastix/CMake/sitkLanguageOptions.cmake:38 (find_package)
SuperBuild.cmake:244 (include)
CMakeLists.txt:26 (include)
After i switching python version into 3.4.0 by pyenv
, the required version of python also switch to "3.4":
CMake Error at /usr/local/Cellar/cmake/3.3.1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find PythonLibs: Found unsuitable version "2.7.6", but required
is exact version "3.4" (found /usr/lib/libpython2.7.dylib)
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.3.1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:386 (_FPHSA_FAILURE_MESSAGE)
/usr/local/Cellar/cmake/3.3.1/share/cmake/Modules/FindPythonLibs.cmake:205 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
/Users/vinllen/opt/elastix/SimpleElastix/CMake/sitkLanguageOptions.cmake:38 (find_package)
SuperBuild.cmake:244 (include)
CMakeLists.txt:26 (include)
It's very strange the required version dynamic change when my python version changed.
At first, i guess maybe it's my problem of cmake-3,3
, so i download a new cmake-3.5
with GUI. Now, i can pass the compile and build, and then installed by python, but when i import the package of SimpleITK
, errors happened again:
>>> import SimpleITK
Fatal Python error: PyThreadState_Get: no current thread
Abort trap: 6
So i seach this problem in stackoverflow and find this solution, i got the reason: cmake-3.5
with GUI compile SimpleElastix by python-app which is a pre-installed version by OS-X, but the excute python in my command line is installed by homebrew
or pyenv
or macport
or anything else. After failed using otool -L
and install_name_tool
to switch dynmaic link library, i follow this post to switch python by myself:
- Delete old python version by OS-X:
sudo mv /System/Library/Frameworks/Python.framework/Versions/2.7 /System/Library/Frameworks/Python.framework/Versions/2.7_bak
- Move the new python:
sudo mv /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7 /System/Library/Frameworks/Python.framework/Versions/2.7
- Setting group to
wheel
if needed:
sudo chown -R root:wheel /System/Library/Frameworks/Python.framework/Versions/2.7
- Updating the current link if needed:
sudo rm /System/Library/Frameworks/Python.framework/Versions/Current
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7 /System/Library/Frameworks/Python.framework/Versions/Current
Now, rebuild the SimpleElastix
.
Reference:
https://wolfpaulus.com/journal/mac/installing_python_osx/
http://stackoverflow.com/questions/15678153/homebrew-python-on-mac-os-x-10-8-fatal-python-error-pythreadstate-get-no-cu