如何在OSX上正确安装Python以与OpenCV一起使用? [英] How to properly install Python on OSX for use with OpenCV?

查看:85
本文介绍了如何在OSX上正确安装Python以与OpenCV一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去的几天里,我试图使opencv与我的Python 2.7安装一起使用.我不断收到错误消息,说每次尝试导入cv"都找不到opencv模块.

I spent the past couple of days trying to get opencv to work with my Python 2.7 install. I kept getting an error saying that opencv module was not found whenever I try "import cv".

然后我决定尝试使用Macports安装opencv,但这没用.

I then decided to try installing opencv using Macports, but that didn't work.

接下来,我尝试了Homebrew,但这还是行不通的.

Next, I tried Homebrew, but that didn't work either.

最终,我发现我应该这样修改PYTHONPATH: 导出PYTHONPATH ="/usr/local/lib/python2.6/site-packages/:$ PYTHONPATH"

Eventually, I discovered I should modify the PYTHONPATH as such: export PYTHONPATH="/usr/local/lib/python2.6/site-packages/:$PYTHONPATH"

我的问题是我找不到/usr/local/lib/python2.*...etc 该文件夹根本不存在

My problem is that I didn't find /usr/local/lib/python2.*...etc The folder simply doesn't exist

所以我的问题是这样的: 如何在OS X Snow Leopard上正确安装Python以使其与opencv一起使用?

So my question is this: How do I properly install Python on OS X Snow Leopard for it to work with opencv?

非常感谢

推荐答案

我自己花了几天时间.对我来说,问题在于OpenCV安装程序找不到正确的python安装.尽管我已经使用自制软件升级了python,并且正在为python使用virtualenv,但它仍默认为MacOS安装的版本.我在这里总结了大部分设置: https://gist.github.com/4150916

I spent a couple days on this myself. For me, the problem was that that OpenCV installer was not finding the right python installation. It was defaulting to the MacOS-installed version despite the fact that I had upgraded python with homebrew and was using a virtualenv for python. I have collected most of my setup in a gist here: https://gist.github.com/4150916

使用自制程序获取所有依赖项,然后下载OpenCV tarball并进行编译,确保指定所有与python相关的配置选项.

Use homebrew to get all the dependencies, but then download the OpenCV tarball and compile yourself being sure to specify all the python related configuration options.

假设一个名为'opencv'的虚拟环境...

Assuming a virtualenv named 'opencv'...

cd OpenCV-2.4.3/
mkdir release
cd release
cmake -D PYTHON_EXECUTABLE=$WORKON_HOME/opencv/bin/python \
 -D PYTHON_PACKAGES_PATH=$WORKON_HOME/opencv/lib/python2.7/site-packages \
 -D INSTALL_PYTHON_EXAMPLES=ON\
 -D PYTHON_INCLUDE_DIR=/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Headers\
 -D PYTHON_LIBRARY=/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib\
..
make -j8
make install

这篇关于如何在OSX上正确安装Python以与OpenCV一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆