无法在OSX中的python中导入cv2

时间:2021-09-19 18:24:33

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.

我已经尝试了几乎所有在线解决方案列表,但无法正常工作。

6 个解决方案

#1


28  

I do not know what pip install cv2 actually installs... but is surely not OpenCV. pip install cv2 actually installs this, which are some blog distribution utilities, not sure what it is, but it is not OpenCV.

我不知道pv 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,但不是neccesarilly为您提供最新版本或完全优化的版本:

https://web.archive.org/web/20171218032016/http://www.mobileway.net/2015/02/14/install-opencv-for-python-on-mac-os-x/

#2


63  

You can install by

你可以安装

pip install opencv-python

#3


6  

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,可能需要尝试此操作。

#4


1  

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

#5


0  

You can install by

你可以安装

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

#6


0  

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):

  1. Download Miniconda
  2. Download Anaconda
  3. Locate to the director that contains the Miniconda file and run bash Miniconda3-latest-MacOSX-x86_64.sh in Terminal
  4. 找到包含Miniconda文件的控制器并在终端中运行bash Miniconda3-latest-MacOSX-x86_64.sh

  5. Follow the prompts to install Anaconda
  6. 按照提示安装Anaconda

  7. Run conda install -c conda-forge nb_conda
  8. 运行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不起作用,就像有人推荐我遇到同样的问题时。希望这可以帮助!

#1


28  

I do not know what pip install cv2 actually installs... but is surely not OpenCV. pip install cv2 actually installs this, which are some blog distribution utilities, not sure what it is, but it is not OpenCV.

我不知道pv 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,但不是neccesarilly为您提供最新版本或完全优化的版本:

https://web.archive.org/web/20171218032016/http://www.mobileway.net/2015/02/14/install-opencv-for-python-on-mac-os-x/

#2


63  

You can install by

你可以安装

pip install opencv-python

#3


6  

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,可能需要尝试此操作。

#4


1  

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

#5


0  

You can install by

你可以安装

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

#6


0  

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):

  1. Download Miniconda
  2. Download Anaconda
  3. Locate to the director that contains the Miniconda file and run bash Miniconda3-latest-MacOSX-x86_64.sh in Terminal
  4. 找到包含Miniconda文件的控制器并在终端中运行bash Miniconda3-latest-MacOSX-x86_64.sh

  5. Follow the prompts to install Anaconda
  6. 按照提示安装Anaconda

  7. Run conda install -c conda-forge nb_conda
  8. 运行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不起作用,就像有人推荐我遇到同样的问题时。希望这可以帮助!