[英]installing opencv3 for python3 in OSX
So I followed this tutorial and got this error: 所以我遵循了本教程并得到了这个错误:
brew link --overwrite eigen
brew install opencv3 --with-python3 --with-contrib
wrote this in ~/.profile
and sourced it: 在~/.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'
Can someone please guide me what is wrong and how to fix it? 有人可以指导我有什么问题以及如何解决它?
UPDATE: 更新:
I tried this too: 我也试过这个:
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
Since you installed OpenCV3 using Homebrew, your symlink might be corrupted. 由于您使用Homebrew安装了OpenCV3,因此您的符号链接可能已损坏。
Since the current version of OpenCV in homebrew/science is 3.1.0, your symlink probably should point to 由于当前版本的Homebrew / science中的OpenCV是3.1.0,你的符号链接可能应该指向
/usr/local/Cellar/opencv3/3.1.0_3/lib/python3.5/site-packages
3.1.0_3 and python3.5 might differ on your system, so just see for yourself what directories are in /usr/local/Cellar. 3.1.0_3和python3.5可能在您的系统上有所不同,所以只需自己查看/ usr / local / Cellar中的目录。
BTW I didn't need to link anything after doing 顺便说一句,我做完后不需要链接任何东西
brew ln --force opencv3
You need to link your opencv to python site-packages 您需要将opencv 链接到python站点包
Link cv.py and cv2.so using ln -s [cellar-opencv-site-packages-path] [lib-python-site-packages-path]
使用ln -s [cellar-opencv-site-packages-path] [lib-python-site-packages-path]
链接cv.py和cv2.so ln -s [cellar-opencv-site-packages-path] [lib-python-site-packages-path]
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 will be based on opencv and python version. Path将基于opencv和python版本。
Here it is - [opencv3/3.1.0_3]
and [python3.4.1]
这是 - [opencv3/3.1.0_3]
和[python3.4.1]
In short, Copy/Link cv.py and cv2.so from /usr/local/Cellar/opencv3/[[version]]/lib/python[[version]]/site-packages/
to /usr/local/lib/python[[version]]/site-packages/
简而言之,从/usr/local/Cellar/opencv3/[[version]]/lib/python[[version]]/site-packages/
到/usr/local/lib/python[[version]]/site-packages/
复制/链接cv.py和cv2.so /usr/local/lib/python[[version]]/site-packages/
OR you can also add opencv site-packages to PYTHONPATH 或者您也可以将opencv site-packages添加到PYTHONPATH
export PYTHONPATH=$PYTHONPATH:/usr/local/Cellar/opencv3/3.1.0_3/lib/python3.4.1/site-packages/
source ~/.profile
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.