如何安装 openCV_python 而没有导入 cv2 错误?

how to install openCV_python with no import cv2 error?

我正在尝试在我的 mac 上安装 OpenCV-python,我使用了以下内容:

$pip install opencv-python

这给了我以下错误:

$pip install opencv-python
Collecting opencv-python
  Using cached opencv_python-3.4.0.12-cp27-cp27m macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Collecting numpy>=1.11.1 (from opencv-python)
  Using cached numpy-1.14.2-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
matplotlib 1.3.1 requires nose, which is not installed.
matplotlib 1.3.1 requires tornado, which is not installed.
Installing collected packages: numpy, opencv-python
  Found existing installation: numpy 1.8.0rc1
Cannot uninstall 'numpy'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

然后我尝试了 pip install --upgrade matplotlib,但没有任何改变。它只是告诉我:

matplotlib 2.2.2 requires backports.functools-lru-cache, which is not installed.
matplotlib 2.2.2 has requirement numpy>=1.7.1, but you'll have numpy 1.8.0rc1 which is incompatible.

我在网上找到了很多安装 openCV-python 的方法,例如: https://www.pyimagesearch.com/2015/06/15/install-opencv-3-0-and-python-2-7-on-osx/

我在另一个 mac 上安装了,但我的代码中出现了很多 import cv2 问题。 如果有人有安装 openCV-python.

的好的解决方案或建议,我将非常高兴

谢谢

总而言之,macOS 预装了 Python,您不应混淆安装的软件包,因为某些系统实用程序依赖于它们。

https://docs.python.org/3.7/using/mac.html

The Apple-provided build of Python is installed in /System/Library/Frameworks/Python.framework and /usr/bin/python, respectively. You should never modify or delete these, as they are Apple-controlled and are used by Apple- or third-party software. Remember that if you choose to install a newer Python version from python.org, you will have two different but functional Python installations on your computer, so it will be important that your paths and usages are consistent with what you want to do.

你应该看看 venv or virtualenv

您可以阅读此答案: 它将帮助您完成基础知识。

简而言之,解决你的问题:

$ python3 -m venv ./project-name
$ . ./project-name/bin/activate
$ pip install opencv-python

要离开虚拟环境,只需:

$ deactivate