how to install openCV_python with no import cv2 er

2019-08-12 00:04发布

I am trying to install the OpenCV-python on my mac and i have used the following:

$pip install opencv-python

which gave me the following error:

$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.

Then i did try the pip install --upgrade matplotlib which didnot change anything. It just show me:

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.

As I found many ways to install the openCV-python in the internet like: https://www.pyimagesearch.com/2015/06/15/install-opencv-3-0-and-python-2-7-on-osx/

and I installed on my other mac but i got import cv2 problem alot in my codes. I will be more than happy if anyone have a good solution or recommendation to install the openCV-python.

Thanks

1条回答
地球回转人心会变
2楼-- · 2019-08-12 00:19

In summary, macOS comes with the Python preinstalled and you should not mess with the packages installed as some system utilities depend on them.

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.

You should take a look on either venv or virtualenv.

You can read this answer: https://stackoverflow.com/a/41972262/4796844 that will get you through the basics.

In a nutshell, to solve your problem:

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

And to leave the virtual environment, simply:

$ deactivate
查看更多
登录 后发表回答