0

I am trying to create a Motion capture program on mac Visual Studio Code and the following code:

from imutils.video import VideoStream
import cv2 ## also tried from cv2 import cv2
...

gave me the following error:

Traceback (most recent call last):
  File "/-------/--------/MotionCapture/index.py", line 3, in <module>
    from cv2 import cv2
ImportError: No module named cv2

how can i fix this? also yes i do have all of the modules installed

  • Are you sure vscode is using the python where you installed opencv? What is the name of the .py file? – eyllanesc Oct 28 '21 at 01:55
  • @eyllanesc its index.py –  Oct 28 '21 at 02:01
  • Don't you have some file or folder called cv2 next to index.py? – eyllanesc Oct 28 '21 at 02:03
  • @eyllanesc In that case the error would not be `ImportError: No module named cv2`. – John Gordon Oct 28 '21 at 02:03
  • How did you install the cv2 module? What exact command did you use? – John Gordon Oct 28 '21 at 02:04
  • @JohnGordon There are many causes, at this moment I am attacking from 2 sides: 1. That vscode is using a different python than the one where I install opencv, 2. Or that there is a folder or directory that hides opencv package – eyllanesc Oct 28 '21 at 02:06
  • @eyllanesc case 2 cannot be the issue. – John Gordon Oct 28 '21 at 02:08
  • @JohnGordon i used the following: ```pip install mediapipe opencv-python, pip install opencv-python, pip install imutils``` –  Oct 28 '21 at 02:09
  • Show us the output of `pip --version`, and also show us the output of running this code in visual studio: `import sys; print(sys.version)` – John Gordon Oct 28 '21 at 02:10
  • @user14250770 At the bottom left point the path of the python, if it is different from where you installed then double click and select the correct python. Another option is that you open the vscode terminal and execute: `python -m pip install python-opencv` – eyllanesc Oct 28 '21 at 02:11
  • pip 21.3.1 from /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip (python 3.6) VS CODE: 2.7.16 (default, Apr 17 2020, 18:29:03) [GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc- –  Oct 28 '21 at 02:12
  • From that output, it looks like you have (at least) two versions of Python installed on your system. Pip installed the cv2 module for python 3.6, but vs code is using python 2.7. That's why your code can't find the cv2 module. Change your vs code to use python 3.6. – John Gordon Oct 28 '21 at 02:14
  • also got this ```Could not import runpy module``` –  Oct 28 '21 at 02:14
  • ok how would i make VSC use the 3.6 vers –  Oct 28 '21 at 02:15
  • @user14250770 See https://code.visualstudio.com/docs/python/environments – eyllanesc Oct 28 '21 at 02:58

0 Answers0