Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 18819

'import cv2' works fine in spyder and in command prompt BUT gives error when a program is run from Anaconda Prompt

$
0
0

I am trying to use opencv in my code. It works fine when I run it directly from spyder or from command prompt using import cv2.I have a small code in file 'test_opencv_installation.py' that contains import cv2 as following

import cv2image = cv2.imread("logo.png")gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)cv2.imshow("OpenCV logo", image)cv2.imshow("OpenCV logo gray format", gray_image)cv2.waitKey(0)cv2.destroyAllWindows()

However, The following error occurred when running the file "C:\Anaconda\envs\my_opencv\test_opencv_installation.py":

The module 'cv2' could not be found or imported.

This is the full error message:

Traceback (most recent call last):File "C:\Anaconda\envs\my_opencv\test_opencv_installation.py", line 6, in <module>import cv2ModuleNotFoundError: No module named 'cv2'

enter image description here

Please share your experience and kindly suggest me any solution to this.Thanks....


Viewing all articles
Browse latest Browse all 18819

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>