简体   繁体   中英

opencv runs in python but not in spyder

I am a complete beginner to opencv . I wrote this code in spyder and it shows no module named 'cv2'

import cv2
img = cv2.imread('D:\ML\img1.jfif',1)
cv2.imshow('D:\ML\img1.jfif',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

but the same code works in the python cmd

any help is appreciated. Thank you

Probably a diffent Python interpreter / executable for each case:

You can check:

import sys
print(sys.executable)

There are multiple reasons why this could be the case.

  1. May you work in a virtual environment in which your cv2 package is not "known".
  2. You have the wrong cv2 package for your python version.
  3. Maybe you use the wrong interpreter (eg. if you have a python2 and python3 interpreter but pip installed cv2 for the wrong one).

Plase provide which python interpreter you have set up for your Spyder, if this is the only installed python on your path and how you installed cv2.

Best regards and good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM