-2

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?

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
zen
  • 1
  • 1
  • 1
    Well, have you installed `cv2`? I believe it's packaged as `opencv-python`, but I've never used it myself. If you have, there's an existing question: [Unable to import a module that is definitely installed](/q/14295680/4518341). – wjandrea Aug 06 '23 at 23:41
  • BTW, welcome to Stack Overflow! Check out the [tour], and [How to ask a good question](/help/how-to-ask) for tips. – wjandrea Aug 06 '23 at 23:41
  • i installed python3 install opencv-python does not work :/ python or pip commands do not work – zen Aug 06 '23 at 23:58
  • So, what *exactly* is giving you the error? – juanpa.arrivillaga Aug 07 '23 at 00:31

1 Answers1

0

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.

zen
  • 1
  • 1
  • You should accept the answer by clicking on tick icon ✅ which is at left of the answer, so that community can understand that the question has been answered. – JialeDu Aug 31 '23 at 01:35