skip to Main Content

I have successfully installed Python 3 utilizing Homebrew and can readily execute Python 3 commands within the terminal, as well as run my scripts without any issues.

However, I’m encountering a challenge when trying to execute my code within Visual Studio Code. I consistently receive the following error upon attempting to run my script:

Traceback (most recent call last):
  File "/Users/zen/Desktop/W/coding/Scan/test.py", line 1, in <module>
    import cv2
ModuleNotFoundError: No module named 'cv2'

This issue persists for other import statements as well. Notably, simpler commands such as print('hello world') execute flawlessly.

I’ve ensured that the path to my Python interpreter is correctly specified in the settings.json file of VS Code.

Would anyone be able to provide assistance regarding this matter?

2

Answers


  1. Chosen as BEST ANSWER

    I just solved the error by going into the code runner settings.json, executer map and change

    {
        "code-runner.executorMap": {
            "python": "python -u"
        }
    }
    

    into

    {
        "code-runner.executorMap": {
            "python": "python3 -u"
        }
    }
    

    For people who has same problems.


  2. You need to install the package in Visual Studio Code. Start a new terminal session in VS code and enter the following pip install opencv-python

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search