1

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?

  • Are you already install libopencv-dev and python-opencv? – xdhe Jun 18 '16 at 14:00
1

If you see here, this is not a raspberry related issue, but more a standard virtualenv issue. Seems that not all aliases, packets and libraries of virtualenv are correctly loaded when using sudo.

The link recommends to run directly the virtual environment's Python executable with sudo. Something like:

sudo ./<virtualenv name>/bin/python <script>
0

For me I don't like the Virtual Environment Wrapper. So I install OpenCV without it. If you would like to install OpenCV again from Scratch. Here is my cheat sheet. It works fine for me and for my colleagues. I recommend you to stick to the cheat sheet, especially in step 12. Hope it works well for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.