安装并运行Mac Python Open CV [英] Install and run Mac Python Open CV

查看:298
本文介绍了安装并运行Mac Python Open CV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了python,安装了python 3,使用自制软件安装了opencv,还通过GUI安装了python,并遵循了几年前编写的各种说明页面和注释.

I have python installed, python 3 installed, installed opencv using homebrew, also installed python through the GUI, followed various instructions pages and comments written several years ago.

我想使用OpenCV来检测最亮和最暗的像素,并在它们之间画线,以根据每个单元格中的亮点和暗点将图像雕刻到单元格中.我认为这是该软件的合理应用程序.

I'd like to use OpenCV to detect brightest and darkest pixels and draw line between them to carve the image up into cells based on the bright and dark points in each cell. I assume this a reasonable application for this software.

当我转到python,进行任何安装并输入import cv时,都会收到无模块"消息.

When I go to python, any installation, and enter import cv I get a 'no module' message.

推荐答案

首先,您需要确定是要运行Python2还是运行Python3.我主张使用Python 3,首先,因为这显然是一个新项目,因此您可以以及使用最新,最出色的Python,其次是因为Python 2的使用寿命为9天.

First, you need to decide whether you want to run Python2 or Python 3. I would advocate Python 3, firstly because this is clearly a new project so you may as well use the latest and greatest Python, and secondly since Python 2 is end-of-lifed in 9 days' time.

然后,您需要确定是否要使用Apple提供的Python,使用/usr/bin还是 homebrew 提供的Python.当您安装 homebrew Python时,我建议您使用 homebrew ,因为您可以删除整个内容,如果您将所有Apple-提供的补丁程序,操作系统升级以及它们对Python的其他使用将不受影响.快乐的日子!

Then you need to decide if you want to use the Apple-supplied Python, in /usr/bin or the homebrew supplied Python. As you have installed homebrew Python, I would advocate using the homebrew one because you can delete the whole thing and re-install it if you mess it up while all the Apple-supplied patches, OS upgrades and their other uses of their Python will remain unaffected. Happy days!

因此,您想使用 homebrew Python3.现在,通过运行以下命令检查 homebrew 告诉您什么:

So, you want to use homebrew Python 3. Now check what homebrew tells you, by running:

brew info python

未版本化的符号链接pythonpython-configpip等指向 python3python3-configpip3等已分别 安装到/usr/local/opt/python/libexec/bin

Unversioned symlinks python, python-config, pip etc. pointing to python3, python3-config, pip3 etc., respectively, have been installed into /usr/local/opt/python/libexec/bin

这意味着如果您要运行pythonpip(没有版本号,而不是python3pip3)并希望启动Python 3及其相应的pip,则需要将/usr/local/opt/python/libexec/bin放在PATH开头的bash profile(可能是$HOME/.bash_profile)中:

That means if you want to run python and pip (without a version number, as opposed to python3 and pip3) and expect that to start Python 3 and its corresponding pip, you need to put /usr/local/opt/python/libexec/bin at the start of your PATH in your bash profile (probably $HOME/.bash_profile):

export PATH=/usr/local/opt/python/libexec/bin:$PATH

然后启动一个新的终端,并在键入python时检查哪个Python运行:

Then start a new Terminal and check which Python runs when you type python:

type python

如果您处在正确的轨道上,则必须报告以下内容:

And it must report as follows if you are on the right track:

python is /usr/local/opt/python/libexec/bin/python

然后,您可以检查哪个Python版本:

Then, you can check which Python version that is with:

python -V

它应该是:

Python 3.7.5

现在您可以通过以下方式安装OpenCV:

Now you can install OpenCV with:

pip install opencv-python

然后使用以下命令将其加载到解释器中:

Then load it in the interpreter with:

import cv2


如果出于某种原因,您想运行旧的v2.7 Python,或者冒着通过安装冲突模块而弄乱 macOS 的安装的风险,请无视我的回答.


If, for some reason, you want to run the old v2.7 Python, or risk messing up the installation of your macOS by installing clashing modules, just disregard my answer.

这篇关于安装并运行Mac Python Open CV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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