无法在Anaconda中运行cv2

时间:2018-02-21 03:57:44

标签: python python-3.x opencv anaconda

我是编码的初学者,想学习机器学习。所以我已经安装了Anaconda 4.4.1和python 3.6以及Open CV 3.我已按照本网站https://chrisconlan.com/installing-python-opencv-3-windows/的要求完成了所有工作。安装完成后,我尝试运行一行代码,如下所示:

import numpy as np

import cv2

img = cv2.imread('dog.jpg', 0)

print(img)

输出是:

runfile('C:/Users/Russell/Desktop/Python_Test/cv2 test.py', wdir='C:/Users/Russell/Desktop/Python_Test')
Traceback (most recent call last):

  File "<ipython-input-1-8ac86397d1f0>", line 1, in <module>
    runfile('C:/Users/Russell/Desktop/Python_Test/cv2 test.py', wdir='C:/Users/Russell/Desktop/Python_Test')

  File "C:\Anaconda\envs\myWindowsCV\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
    execfile(filename, namespace)

  File "C:\Anaconda\envs\myWindowsCV\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/Russell/Desktop/Python_Test/cv2 test.py", line 2, in <module>
    import cv2

  File "C:\Users\Russell\Desktop\Python_Test\cv2.py", line 4, in <module>
    img = cv2.imread('dog.jpg')

AttributeError: module 'cv2' has no attribute 'imread'

任何人都可以帮我吗?真的很感激。

0 个答案:

没有答案