1

I have installed opencv by following the instruction Here. my code that imports opencv works fine when I run it from terminal. However, when I run my code from pycharm I get:

ImportError: No module named cv2

I have set the python interpreter to my desired virtual environment in Pycharm.

Community
  • 1
  • 1
MAS
  • 4,503
  • 7
  • 32
  • 55

1 Answers1

0

Background : OP is using SPE Stani's python editor. OP has installed OpenCV /opt/ros/hydro/lib/python2.7/dist-packages which is not detected by the above mentioned editor. Adding this path to PYTHONPATH doesn't solve the issue.

Solution (any one of the below):

  1. Add this path to sys.path and put it in every file.

import sys sys.path.append('/opt/ros/hydro/lib/python2.7/dist-packages')

  1. Copy cv2.so file to any directory in the sys.path.

This may help you.

Usman Maqbool
  • 3,351
  • 10
  • 31
  • 48