如何在 OSX 上正确安装 Python 以与 OpenCV 一起使用?
过去几天我一直在尝试让 opencv 与我安装的 Python 2.7 一起工作。每当我尝试“导入 cv”时,我总是收到一条错误消息,提示未找到 opencv 模块。
然后我决定尝试使用 Macports 安装 opencv,但这不起作用。
接下来,我尝试了 Homebrew,但也不起作用。
最终,我发现我应该这样修改 PYTHONPATH: 导出 PYTHONPATH="/usr/local/lib/python2.6/site-packages/:$PYTHONPATH"
我的问题是我没有找到 /usr/local/lib/python2.*...etc 该文件夹根本不存在
所以我的问题是这样的: 如何在 OS X Snow Leopard 上正确安装 Python 以使其与 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".
I then decided to try installing opencv using Macports, but that didn't work.
Next, I tried Homebrew, but that didn't work either.
Eventually, I discovered I should modify the PYTHONPATH as such:
export PYTHONPATH="/usr/local/lib/python2.6/site-packages/:$PYTHONPATH"
My problem is that I didn't find /usr/local/lib/python2.*...etc
The folder simply doesn't exist
So my question is this:
How do I properly install Python on OS X Snow Leopard for it to work with opencv?
Thanks a lot,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我自己花了几天时间在这上面。对我来说,问题是 OpenCV 安装程序没有找到正确的 python 安装。尽管我已经使用自制软件升级了 python 并且使用了 python 的 virtualenv,但它还是默认为 MacOS 安装的版本。我在这里收集了大部分设置的要点:
https://gist.github.com/4150916
使用 homebrew 获取所有依赖项,然后下载OpenCV tarball 并自行编译,确保指定所有与 python 相关的配置选项。
假设一个名为“opencv”的 virtualenv...
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
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.
Assuming a virtualenv named 'opencv'...
您需要使用 python2.7 安装来安装该模块。将 PYTHONPATH 指向 2.6 下安装的东西以在 2.7 下运行是一个坏主意。
根据您想要的安装方式,执行
python2.7 setup.py
或easy_install-2.7 opencv
等操作进行安装。fwiw,在 OS X 上,模块通常安装在 /System/Library/Frameworks/Python.framework/ 下,但您几乎不需要知道站点包中安装的任何内容的物理位置;如果 Python 在没有帮助的情况下无法找到它们,那么说明它们安装错误。
You need to install the module using your python2.7 installation. Pointing your PYTHONPATH at stuff installed under 2.6 to run under 2.7 is a Bad Idea.
Depending on how you want to install it, do something like
python2.7 setup.py
oreasy_install-2.7 opencv
to install.fwiw, on OS X the modules are usually installed under /System/Library/Frameworks/Python.framework/ but you should almost never need to know where anything installed in your site packages is physically located; if Python can't find them without help you've installed them wrong.
使用 Homebrew 安装 OpenCV
设置 Python
取决于您的安装位置 - OS X 默认
或 - Homebrew Python
然后创建符号链接
上述方法源自 博客文章。
Installing OpenCV with Homebrew
Setting up Python
Depending on your install location - OS X Default
or - Homebrew Python
Then create the symbolic link
The above method sourced from a blog post.
我搜索并尝试用 python3 安装 opencv3 3天。有些链接建议使用 Brew 和一些虚拟环境,有些链接建议安装 xcode 但在我的情况下都失败了。
不要使用linux步骤在Mac上安装opencv-python。 Mac 的问题是 Mac 已经安装了 Python 2.7。最重要的是,安装和链接所有站点包几乎没有问题,我们最终会遇到错误。
我将分享我所做的:在 Mac 上安装完整包 opencv3、numpy、matplotlib、notebook、spyder 等的简单步骤。
安装 anaconda,它会创建一个目录并安装其中的所有内容
使用此链接 -> https://www.continuum.io/downloads
下载 command-line-install
下载后,转到终端并下载 anaconda 的位置。
$ bash Anaconda3-4.3.0-MacOSX-x86_64.sh
安装将要求您将路径附加到 .bash_profile >>>说是
转到主目录,运行 .bash_profile
$ source .bash_profile
检查python,应该指向
$ 哪个Python
$ /.../anaconda/bin/python
最后一步
$ pip install opencv-pyhton
$ python
$ import cv2
如果没有错误,我们就可以开始了。
I searched and tried installing opencv3 with python3 for 3 days. Some links suggest for Brew and some virtual env, some say install xcode but all failed in my case.
Dont use linux steps to instal opencv-python on Mac. Problem with Mac is Python 2.7 is already installed by Mac. On top of that installing and linking all site-packages is little problematic and we end up with errors.
I'll share what I did: easy steps to install complete package opencv3, numpy, matplotlib, notebook, spyder etc.. on Mac.
Install anaconda, it creates a directory and install everything inside that
use this link -> https://www.continuum.io/downloads
download command-line-install
After download, goto terminal and download location of anaconda.
$ bash Anaconda3-4.3.0-MacOSX-x86_64.sh
Installation will ask you to append path to .bash_profile >> say yes
Goto home directory, run .bash_profile
$ source .bash_profile
check python, should be pointing to
$ which python
$ /.../anaconda/bin/python
Last step
$ pip install opencv-pyhton
$ python
$ import cv2
if no errors, we are good to go.