I have a project I am developing with python3. I would like to add some status LED functions to it.
If I am not root everything is fine, my activated virtualenv is all good, but I cannot use GPIO (for example gpiozero).
If I sudo run my code my virtualenv does not work properly.
Even if I run
sudo /home/me/.virtualenvs/project/bin/python3 mycode.py
Some libraries normally accessible from my virtualenv are not accessible (will not import)
How do I access both my virtualenv and the GPIO libraries within my python code?
1 Answer 1
Either install the libraries you need into the virtualenv using e.g. pip install gpiozero
or when you create your virtualenv, enable site-packages using virtualenv --system-site-packages
.
Be aware that if you install gpiozero into a virtualenv, you also need to install a pin library, probably rpi.gpio
.
-
This answer got me working with my code. Later I found I could also solve the problem by adding myself to the gpio group.deMangler– deMangler2019年12月06日 08:20:48 +00:00Commented Dec 6, 2019 at 8:20
pip3
with the virtual environment active and without using sudo.