Skip to content
Advertisement

import cv2 not working in vscode but working in pycharm

I got import cv2 to work on pycharm but for some reason it does not work on my visual studio code despite doing the same thing I did with pycharm which was to pip install opencv-contrib-python on a virtual enviroment. I created a virtual enviroment in vscode and the file is part of my project file and I selected the virtual enviroment to be my interpreter and even added it to my path and installed opencv-contrib-python in the virtual enviroment but for some reason import cv2 still does not work.

does anyone have ideas on how to get it to work on vscode? it shows the green highlighting color for cv2 but yet it still gives me

Traceback (most recent call last): File “[filename]”, line 1, in import cv2 ImportError: No module named cv2

and when I hover on the highlighted cv2 in import cv2 it shows

(module) cv2 OpenCV Python binary extension loader “cv2” is not accessed. Pylance

also when i ever i click on run code it throws an error but when i do python3 NameOfFile.py it doesn’t show any error.

Advertisement

Answer

Try adding the following code to the setting.json

"code-runner.executorMap": {
            "python": "python3 -u",
        }
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement