0

I'm working on a python project based on OpenCV .. after installing the opencv from this link : http://www.pyimagesearch.com/2016/04/18/install-guide-raspberry-pi-3-raspbian-jessie-opencv-3/ And when i'm in the virtual environment and after importing RPi.GPIO i get that no module named RPi.GPIO

But When i'm outside the virtual environment the RPi.GPIO works properly I have raspbian Jessy on a Raspberry pi 3

1
  • 1
    This looks like SEO effort for pyimagesearch.com. Both question and answer link to the same site, and both are completely meaningless unless you click the link. Commented Dec 2, 2016 at 11:17

2 Answers 2

7

The problem is that you don't have the GPIO module installed in your virtual environment. To correct this, run the following from within your virtual environment:

for Python 2

pip install RPi.GPIO

or for Python 3

pip3 install RPi.GPIO

This will install the module where your virtual environment can find it.

One of the features of virtual environments is that they allow you to manage modules on a project by project basis and avoid conflicts with other projects (e.g. project A requires version 1 and project B requires version 3 of the same module). More info on virtual environments and modules can be found in the Python documentation. Tutsplus has a nice tutorial on Python Virtual Environments

0

As per Steve's answer:

http://www.pyimagesearch.com/2016/05/02/accessing-rpi-gpio-and-gpio-zero-with-opencv-python/

To cite that author:

The reason for this problem is that RPi.GPIO/GPIO Zero were not installed into your Python virtual environment! To fix this issue, all you need to do is use pip to install them into your virtual environment — from there, you’ll be good to go.

But to be honest with you, I don’t think that’s the real issue here!

The real problem is not having a sufficient understanding of what Python virtual environments are and why we use them...

1
  • 1
    We're trying a new policy with regard to informationless link-only answers here. If this post is not edited to contain information that can stand as an answer, however minimal, in 48 hours it will be converted to Community Wiki to simplify having it corrected by the community. Commented Nov 27, 2016 at 22:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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