首頁  >  問答  >  主體

opencv2 - mac下安装opencv python中导入错误

小白一只,安装过程如下
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make
sudo make install

import cv,就出现这个
import cv
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/cv.py", line 1, in <module>

from cv2.cv import *

ImportError: dlopen(/usr/local/lib/python2.7/site-packages/cv2.so, 2): Library not loaded: libopencv_contrib.2.4.dylib
Referenced from: /usr/local/lib/python2.7/site-packages/cv2.so
Reason: unsafe use of relative rpath libopencv_contrib.2.4.dylib in /usr/local/lib/python2.7/site-packages/cv2.so with restricted binary

PHPzPHPz2766 天前756

全部回覆(1)我來回復

  • 怪我咯

    怪我咯2017-04-17 18:03:23

    你的系統是不是Mac 10.11
    系統的安全機制不允許使用不安全的相對連接
    解決方法

    1.關掉這個機制

    1. 重啟 Mac,按住 Command+R 鍵直到 Apple logo 出現,進入 Recovery Mode

    2. 點選 Utilities > Terminal

    3. d在 Terminal 輸入 csrutil disable,之後回車

    4. 重啟 Mac

    2.把相對路徑換成絕對路徑

    GitHub - zsirui/opencv-fix-path-on-OSX: Fix path error when installed OpenCV 3.1.0 through CMake build on OSX/修復在OSX下透過CMake編譯安裝OpenCV3.1.0在python中導入cv路徑錯誤

    回覆
    0
  • 取消回覆