Search code examples
pythonopencvraspberry-pisudo

Python doesn't recognize cv2 when running under sudo


I've installed opencv with python 2.7 using this tutorial. I've created a test python file and everything works fine. But when I try to run it as sudo, it throws an error:

ImportError: No module named cv2

I'm guessing this has to do with permissions.. I need to run it as sudo because I'm using pigpiod in another function.

Any thoughts?


Solution

  • This problem was caused because when I installed opencv I created it in a virtual env. Making a link to the opencv file from outside the env to the opencv library folder fixed it.