opencv: Cannot import cv2 because unsafe use of relative rpath lib in cv2.so with restricted binary
I just update my laptop from Yosemite to El Capitan. When I try to use OpenCV-Python, I got this information:
➜ ~ python
Python 2.7.10 (default, Aug 22 2015, 20:33:39)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/usr/local/lib/python2.7/site-packages/cv2.so, 2): Library not loaded: lib/libopencv_shape.3.0.dylib
Referenced from: /usr/local/lib/python2.7/site-packages/cv2.so
Reason: unsafe use of relative rpath lib/libopencv_shape.3.0.dylib in /usr/local/lib/python2.7/site-packages/cv2.so with restricted binary
>>> exit()
➜ ~ which python
/usr/bin/python
➜ ~ echo $PYTHONPATH
/usr/local/lib/python2.7/site-packages/
➜ ~
I installed OpenCV3.0 by compiling the source code not using homebrew. I find a similar problem description from homebrew-opencv: homebrew-science-issues but quite different with this.
What should I do now?
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 25 (7 by maintainers)
@pranny Thanks !!! it’s work for me
This is because of SIP (System Integrity Protection) introduced in El Capitan link.
I too faced the same issue and came across this SO link. Basically, the relative path dependencies listed in the shared libs need to be changed to absolute paths. There are huge number of these to be corrected in opencv libraries. You can optionally disable SIP. I preferred to change the links instead and wrote the following python snippet.
Change the ABSPATH and LIBPATHS if required. It can be used for other libraries as well. It will create rPathChangeCmd.txt which you can paste in the terminal. It will also create rPathChangeErr.txt in case of any errors. I would suggest check error file (if created) before pasting the commands.
Static build should help (via CMake):
cmake -DBUILD_SHARED_LIBS=OFF ...
Solved this issue:
In conda currently, Python 3 doesn’t support opencv 3 or 2. So I changed from python 3 to 2.
and installed opencv by the following command
conda install -c menpo opencv=2.4.11
and did import cv2
and it is working