【问题标题】:Opencv installed on mac but unable to use it through python console在mac上安装了opencv但无法通过python控制台使用它
【发布时间】:2016-06-26 03:37:18
【问题描述】:

无法在 macbook OS X Yosemite Ver 10.10.5 中安装“opencv”

尝试了默认安装,没有帮助然后我安装了Python的Anaconda发行版,之后再次尝试以下,我收到消息说opencv已安装,但我无法通过python控制台使用它。安装Anaconda后,我跟着this tutorial安装opencv

  $sudo chmod 777 /usr/local/include/
  $brew link eigen jpeg libpng libtiff ilmbase openexr numpy
  $sudo chmod 777 /usr/local/lib/pkgconfig
  $brew link eigen jpeg libpng libtiff ilmbase openexr numpy
  $brew install opencv --evn=std
  $brew link eigen jpeg libpng libtiff ilmbase openexr numpy
  $sudo chmod 777 /usr/local/lib/
  $brew link eigen jpeg libpng libtiff ilmbase openexr numpy
  $brew install opencv --evn=std
  $python
  $mkdir -p /Users/vikramchindam1/.local/lib/python2.7/site-packages
  $echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/vikramchindam1/.local/lib/python2.7/site-packages/homebrew.pth

然后启动python控制台

 $python

>>> import cv
Python 2.7.11 |Anaconda 2.5.0 (x86_64)| (default, Dec  6 2015, 18:57:58) 

[GCC 4.2.1 (Apple Inc. build 5577)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

Anaconda is brought to you by Continuum Analytics.

Please check out: http://continuum.io/thanks and https://anaconda.org

>>> import cv

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

ImportError: No module named cv

我在一段时间内多次安装了 Anaconda,这是一个问题吗?以下是我的 .bash_profile 中的条目

alias textedit='open -a TextEdit'

# added by Anaconda 2.2.0 installer
export PATH="/Users/vikramchindam1/anaconda/bin:$PATH"

##
# Your previous /Users/vikramchindam1/.bash_profile file was backed up as /Users/vikramchindam1/.bash_profile.macports-saved_2015-06-06_at_15:09:19
##

# MacPorts Installer addition on 2015-06-06_at_15:09:19: adding an appropriate PATH variable for use with MacPorts.
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
# Finished adapting your PATH environment variable for use with MacPorts.


# added by Anaconda 2.2.0 installer
export PATH="/Applications/anaconda/bin:$PATH"

# added by Anaconda3 2.3.0 installer
export PATH="/Users/vikramchindam1/Documents/Anaconda-3/anaconda/bin:$PATH"

# added by Miniconda2 3.19.0 installer
export PATH="/Users/vikramchindam1/miniconda2/bin:$PATH"

# added by Anaconda2 2.5.0 installer
export PATH="/Users/vikramchindam1/Installations/Anacon-Python2-7/anaconda/bin:$PATH"
export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH

最后一个条目“export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH”是我在通过这个命令“brew install opencv --env=std”安装opencv后添加的

请帮帮我,提前谢谢。

【问题讨论】:

标签: python macos opencv anaconda


【解决方案1】:

您必须使用“conda”工具在 Anaconda 中安装 OpenCV。您可以尝试在终端中输入。

conda install -c https://conda.binstar.org/menpo opencv

这适用于我的 ubuntu 14.04,我认为它也应该适用于 Mac。

您可以在此链接中找到详细说明,其中我展示了如何在 Anaconda 中安装 OpenCV。

http://stackoverflow.com/questions/38787748/installing-opencv-3-1-with-anaconda-python3/39240127#39240127

希望对你有帮助 =)

【讨论】:

    猜你喜欢
    • 2021-09-20
    • 2020-12-12
    • 2019-12-10
    • 1970-01-01
    • 2015-05-09
    • 1970-01-01
    • 1970-01-01
    • 2018-06-26
    • 2018-04-30
    相关资源
    最近更新 更多