Proper way to install Python modules?

Hello,

I’m dabbling with this Python module:

The only way I can get pip to install it on the Le Potato /w headless Raspbian is with this command:

pip3 install --break-system-packages adafruit-circuitpython-bno055

I would create a virtual python environment and use that instead, but I can’t figure out how to add the correct gpiod module into the virtual environment. This is the one that is already pre-installed in the Raspbian image.

I’ve tried making a virtual environment as such:

python3 -m venv tankbot
source tankbot/bin/activate
pip3 install gpiod

But, this is not the right gpiod. I have scripts that work with the pre-installed gpiod module. But when I activate this python virtual environment, I get errors.

from gpiod import Chip, LINE_REQ_DIR_OUT, LINE_REQ_DIR_IN
ImportError: cannot import name 'LINE_REQ_DIR_OUT' from 'gpiod' (/root/tankbot/lib/python3.11/site-packages/gpiod/__init__.py)
  1. What’s the right way to install python modules?
  2. How do I install the the correct gpiod module into a python virtual environment? “The correct gpiod” being the problem, not the creation of the virtual environment.

There’s already a bno055 driver in Linux. There’s no reason to use a hacked userspace driver and manually bitbang the bus like the adafruit library does.

https://docs.kernel.org/iio/bno055.html

You should use the libretech-wiring-tool to create a device-tree overlay that maps the sensor to a GPIO instead.

The need to install other python packages persists, though. How can one safely install other python packages? Or, how can one install the correct “gpiod” within a python virtual environment?