I've been trying to use the gpiozero library lately with one of my opencv projects. Installed gpiozero using pip. Sample code works fine, no issues.

The problem is, my opencv installation is in a virtual environment named "cv". When I try running the same sample code from within my virtual environment, I get an ImportError

ImportError: cannot import name LED

The sample code is as follows

from gpiozero import LED
from time import sleep

led = LED(14)

while True:

Note that this code works perfectly fine outside the cv environment. Inside cv, I can import gpiozero but nothing else. I can't use the LED classes, nor the Button class and all others that I tried.

I tried installing gpiozero within the cv environment but pip reports that the requirement is already satisfied.

I've tried removing gpiozero and reinstalling it inside cv. Didn't work.

How can I make the gpiozero library work inside the cv environment?

Your Answer

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

Browse other questions tagged or ask your own question.