无法在 OSX 中的 python 中导入 cv2
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34853220/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot import cv2 in python in OSX
提问by vinllen
I have installed OpenCV 3.1 in my Mac, cv2 is also installed through pip install cv2
.
我在 Mac 上安装了 OpenCV 3.1,cv2 也是通过pip install cv2
.
vinllen@ $ pip install cv2
You are using pip version 7.1.0, however version 7.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Requirement already satisfied (use --upgrade to upgrade): cv2 in /usr/local/lib/python2.7/site-packages
But it looks like cv2
and cv
cannot be used:
但它看起来像cv2
并且cv
不能使用:
Python 2.7.10 (default, Jul 13 2015, 12:05:58)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cv2
>>> import cv
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cv
I have tried almost all the solutions list online, but cannot work.
我已经尝试了几乎所有在线解决方案列表,但无法正常工作。
采纳答案by Imanol Luengo
I do not know what pip install cv2
actually installs... but is surely notOpenCV.pip install cv2
actually installs this, which are some blog distribution utilities, not sure what it is, but it is notOpenCV.
我不知道pip install cv2
实际安装了什么……但肯定不是OpenCV。pip install cv2
实际上安装了这个,这是一些博客分发实用程序,不确定它是什么,但它不是OpenCV。
To properly install OpenCV, check any of the links @udit043 added in the comment, or refer to any of the tutorials bellow:
要正确安装 OpenCV,请检查评论中添加的任何链接 @udit043,或参考以下任何教程:
Find here a tutorial on how to install OpenCV on OS X: http://www.pyimagesearch.com/2015/06/15/install-opencv-3-0-and-python-2-7-on-osx/
在此处找到有关如何在 OS X 上安装 OpenCV 的教程:http: //www.pyimagesearch.com/2015/06/15/install-opencv-3-0-and-python-2-7-on-osx/
You need to actually compile OpenCV from source and activate python bindings, which takes a while.
您需要从源代码实际编译 OpenCV 并激活 python 绑定,这需要一段时间。
Another option is to use brew
to get OpenCV, but doesn't neccesarilly get you the last version nor a fully optimized one:
另一种选择是用于brew
获取 OpenCV,但不一定会为您提供最新版本或完全优化的版本:
回答by Vijay
Make sure that numpy, other dependency is installed prior installing OpenCV
Also if you installed using PIP then check the installed packages using
确保在安装 OpenCV 之前安装了 numpy,其他依赖项
此外,如果您使用 PIP 安装,则使用
pip freeze
回答by Monica Heddneck
I used
conda install opencv
and it installed fine for me.
我用过
conda install opencv
,对我来说安装得很好。
You might want to try this if you are using Anaconda.
如果您使用的是 Anaconda,您可能想尝试一下。
回答by Alice
You can install by
您可以通过安装
conda install -c https://conda.binstar.org/menpo opencv
回答by Ráfagan
You can install by
您可以通过安装
pip install opencv-python
回答by solo
I had the same problem; here's what worked for me: conda install -c conda-forge nb_conda
我有同样的问题; 这对我有用:conda install -c conda-forge nb_conda
If you haven't already, do the following to get conda up and running on OS X (taken from docs):
如果您还没有,请执行以下操作以在 OS X 上启动并运行 conda(取自docs):
- Download Miniconda
- Download Anaconda
- Locate to the director that contains the Miniconda file and run
bash Miniconda3-latest-MacOSX-x86_64.sh
in Terminal - Follow the prompts to install Anaconda
- Run
conda install -c conda-forge nb_conda
- 下载Miniconda
- 下载蟒蛇
- 定位到包含 Miniconda 文件的director 并
bash Miniconda3-latest-MacOSX-x86_64.sh
在终端中运行 - 按照提示安装Anaconda
- 跑
conda install -c conda-forge nb_conda
You could also try conda install -c conda-forge opencv
and conda install -c conda-forge/label/broken opencv
if step 5 doesn't work, as someone recommended when I had the same problem. Hope this helps!
您也可以尝试conda install -c conda-forge opencv
,conda install -c conda-forge/label/broken opencv
如果第 5 步不起作用,就像我遇到同样问题时有人推荐的那样。希望这可以帮助!
回答by Saurabh Singh
For me installation using condadidn't worked. While installing it using pip worked:
对我来说,使用conda安装没有用。使用 pip 安装它时:
pip install opencv-python
os: macos Catalina
操作系统:Macos Catalina