Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1297

Python • Re: ImportError: libgpiod Python bindings not found

$
0
0
I created a virtual environment in raspberry pi 5 to handle servo motors with a servo driver hat B, and installed adafruit_blinka and manually installed libgpiod with sudo apt install -y python3-libgpiod because of an error but now i am getting this error below

(venv) pi@raspberrypi:~/Desktop/Codes/servo_env $ python3 servo_test.py
ImportError



The way you created your virtual environment for this project is probably critical.

The Raspberry Pi documentation is here - https://www.raspberrypi.com/documentati ... spberry-pi

You probably need to heed the highlighted Note:
NOTE
If you want to inherit the currently installed packages from the system Python, you should create your virtual environment using python -m venv --system-site-packages env.

libgpiod is indeed an instance where you might "want to inherit the currently installed packages from the system Python"



{Edit: Added later...}

Demonstration of the effect of this option -

Code:

avid@rp54bw64full0512:~/Support/libgpiod $ python -m venv isolatedavid@rp54bw64full0512:~/Support/libgpiod $ source isolate/bin/activate(isolate) david@rp54bw64full0512:~/Support/libgpiod $ pythonPython 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import gpiodTraceback (most recent call last):  File "<stdin>", line 1, in <module>ModuleNotFoundError: No module named 'gpiod'>>> (isolate) david@rp54bw64full0512:~/Support/libgpiod $ deactivate david@rp54bw64full0512:~/Support/libgpiod $ python -m venv --system-site-packages sitepackagesdavid@rp54bw64full0512:~/Support/libgpiod $ source sitepackages/bin/activate(sitepackages) david@rp54bw64full0512:~/Support/libgpiod $ pythonPython 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import gpiod>>> (sitepackages) david@rp54bw64full0512:

Statistics: Posted by B.Goode — Sat May 18, 2024 5:06 pm



Viewing all articles
Browse latest Browse all 1297