系统环境
- MacOS 11.4
- MacBook Pro M1
- homebrew
- python3.9
安装命令
brew install opencv@3
注意:截至2021年8月,使用国内源安装会出现404错误。 解决方法:不使用国内源
export HOMEBREW_BOTTLE_DOMAIN=''
具体原因参考:修复homebrew安装软件404问题
路径配置
安装后会输出如下内容:
==> opencv@3
opencv@3 is keg-only, which means it was not symlinked into /opt/homebrew,
because this is an alternate version of another formula.
If you need to have opencv@3 first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/opencv@3/bin:$PATH"' >> ~/.zshrc
For compilers to find opencv@3 you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/opencv@3/lib"
export CPPFLAGS="-I/opt/homebrew/opt/opencv@3/include"
For pkg-config to find opencv@3 you may need to set:
export PKG_CONFIG_PATH="/opt/homebrew/opt/opencv@3/lib/pkgconfig"
当我按照要求配置路径后,python中还是找不到cv2。
解决方法
检验
python3
>>> import cv2
>>>
|