所以我跟着this tutorial并得到了这个错误:
brew link --overwrite eigen
brew install opencv3 --with-python3 --with-contrib
在~/.profile
中写了这个并且来源:
export PYTHONPATH=$PYTHONPATH:/usr/local/Cellar/opencv3/3.0.0/lib/python3.4/site-packages
source ~/.profile
python3
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 00:54:21)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] 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: No module named 'cv2'
有人可以指导我出了什么问题以及如何解决它?
更新:
我也试过了:
Monas-MacBook-Pro:build mona$ brew ln --force opencv3
Linking /usr/local/Cellar/opencv3/3.1.0_3...
Error: Could not symlink bin/opencv_annotation
Target /usr/local/bin/opencv_annotation
is a symlink belonging to opencv. You can unlink it:
brew unlink opencv
To force the link and overwrite all conflicting files:
brew link --overwrite opencv3
To list all files that would be deleted:
brew link --overwrite --dry-run opencv3
Monas-MacBook-Pro:build mona$ brew link --overwrite opencv3
Warning: opencv3 is keg-only and must be linked with --force
Note that doing so can interfere with building software.
Monas-MacBook-Pro:build mona$ brew link --force --overwrite opencv3
Linking /usr/local/Cellar/opencv3/3.1.0_3... 551 symlinks created
答案 0 :(得分:0)
由于您使用Homebrew安装了OpenCV3,因此您的符号链接可能已损坏。
由于当前版本的Homebrew / science中的OpenCV是3.1.0,你的符号链接可能应该指向
/usr/local/Cellar/opencv3/3.1.0_3/lib/python3.5/site-packages
3.1.0_3和python3.5可能在您的系统上有所不同,所以只需自己查看/ usr / local / Cellar中的目录。
BTW我不需要在做完
后链接任何东西brew ln --force opencv3
答案 1 :(得分:0)
您需要链接您的opencv到python site-packages
使用ln -s [cellar-opencv-site-packages-path] [lib-python-site-packages-path]
链接 cv.py 和 cv2.so
ln -s /usr/local/Cellar/opencv3/3.1.0_3/lib/python3.4.1/site-packages/cv.py /usr/local/lib/python3.4.1/site-packages/cv.py
ln -s /usr/local/Cellar/opencv3/3.1.0_3/lib/python3.4.1/site-packages/cv2.so /usr/local/lib/python3.4.1/site-packages/cv2.so
Path将基于opencv和python版本。
这是 - [opencv3/3.1.0_3]
和[python3.4.1]
简而言之,从/usr/local/Cellar/opencv3/[[version]]/lib/python[[version]]/site-packages/
复制/链接 cv.py 和 cv2.so 到/usr/local/lib/python[[version]]/site-packages/
或者您也可以将opencv site-packages添加到PYTHONPATH
export PYTHONPATH=$PYTHONPATH:/usr/local/Cellar/opencv3/3.1.0_3/lib/python3.4.1/site-packages/
source ~/.profile