Trilobot module error

I loaded a fresh copy of the raspberry pi OS onto a sd card. Following your install guide all went as expected up until trying example code. The problem is any example I try to run gives me this error: No module named ‘trilobot’ How do I fix this? Where do I find the trilobot module?

Did you do the following?

In the new terminal window type the commands exactly as it appears below (check for typos) and follow the on-screen instructions:

git clone GitHub - pimoroni/trilobot-python cd trilobot-python ./install.sh

Note Libraries will be installed in the “pimoroni” virtual environment, you will need to activate it to run examples:

source ~/.virtualenvs/pimoroni/bin/activate

pimoroni/trilobot-python

Yes I followed the tutorial exactly. The only problem I had prior to the example issue was running “sudo ./install.sh” Here is the error “FATAL: Script should not be run as root. Try ‘./install.sh’ ” So I removed sudo and ran the script, which appeared to run successfully. I answered ‘y’ to all prompts, No Luck. I wiped the sd card and again started from scratch. I get the same error: from trilobot import *
ModuleNotFoundError: No module named ‘trilobot’

How do I fix this or manually obtain the module and install it so python finds it?

IMHO, this virtual environment stuff is a PITA, but there isn’t much choice.
Are you running the examples from command line or from an IDE like Thonny?
Try activating the virtual environment, and running an example from a terminal window / command line.

1 Like

I am running from a ssh’ed terminal. It seams the virtual environment is loaded as part of the originally ran script.

I tried the setup example found on githut which seems to get around the original trilobot module error only to be confronted with the following error:
$ python3 movements.py
Trilobot Example: Movement

Traceback (most recent call last):
File “/home/pi/Pimoroni/trilobot/examples/movements.py”, line 13, in
tbot = Trilobot()
File “/home/pi/.virtualenvs/pimoroni/lib/python3.13/site-packages/trilobot/init.py”, line 134, in init
self.sn3218 = sn3218.SN3218()
~~~~~~~~~~~~~^^
File “/home/pi/.virtualenvs/pimoroni/lib/python3.13/site-packages/sn3218/init.py”, line 26, in init
self.enable_leds(enable_mask)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
File “/home/pi/.virtualenvs/pimoroni/lib/python3.13/site-packages/sn3218/init.py”, line 55, in enable_leds
self.i2c.write_i2c_block_data(I2C_ADDRESS, CMD_ENABLE_LEDS, [
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
enable_mask & 0x3F,
^^^^^^^^^^^^^^^^^^^
(enable_mask >> 6) & 0x3F,
^^^^^^^^^^^^^^^^^^^^^^^^^^
(enable_mask >> 12) & 0X3F])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3/dist-packages/smbus2/smbus2.py”, line 643, in write_i2c_block_data
ioctl(self.fd, I2C_SMBUS, msg)
~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 5] Input/output error
Exception ignored in: <function Trilobot.del at 0x7f96256d40>
Traceback (most recent call last):
File “/home/pi/.virtualenvs/pimoroni/lib/python3.13/site-packages/trilobot/init.py”, line 155, in del
self.sn3218.disable()
AttributeError: ‘Trilobot’ object has no attribute ‘sn3218’
(pimoroni) pi@pi:~/Pimoroni/trilobot/examples $ Trilobot Example: Movement

Traceback (most recent call last):
File “/home/pi/Pimoroni/trilobot/examples/movements.py”, line 13, in
tbot = Trilobot()
File “/home/pi/.virtualenvs/pimoroni/lib/python3.13/site-packages/trilobot/init.py”, line 134, in init
self.sn3218 = sn3218.SN3218()
~~~~~~~~~~~~~^^
File “/home/pi/.virtualenvs/pimoroni/lib/python3.13/site-packages/sn3218/init.py”, line 26, in init
self.enable_leds(enable_mask)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
File “/home/pi/.virtualenvs/pimoroni/lib/python3.13/site-packages/sn3218/init.py”, line 55, in enable_leds
self.i2c.write_i2c_block_data(I2C_ADDRESS, CMD_ENABLE_LEDS, [
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
enable_mask & 0x3F,
^^^^^^^^^^^^^^^^^^^
(enable_mask >> 6) & 0x3F,
^^^^^^^^^^^^^^^^^^^^^^^^^^
(enable_mask >> 12) & 0X3F])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3/dist-packages/smbus2/smbus2.py”, line 643, in write_i2c_block_data
ioctl(self.fd, I2C_SMBUS, msg)
~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 5] Input/output error
Exception ignored in: <function Trilobot.del at 0x7f96256d40>
Traceback (most recent call last):
File “/home/pi/.virtualenvs/pimoroni/lib/python3.13/site-packages/trilobot/init.py”, line 155, in del
self.sn3218.disable()
AttributeError: ‘Trilobot’ object has no attribute ‘sn3218’

Does you Trilobot have an sn3218 18-Channel 8-bit PWM LED Driver?

Yes it has a sn3218 PWM LED Driver IC

Ok, might want to post the code your running. Use the preformatted text button </> to post it in code tags. That will retain the formatting, indents etc.
Do the same with the error message, that should make it easy to see what line of code is erroring, and maybe why?

Thanks for the reply. The error “ModuleNotFoundError: No module named ‘trilobot” Appears when trying basically ANY of the example programs supplied for the Trilobot on Githut.

Each time you open a session I would first run
source ~/.virtualenvs/pimoroni/bin/activate
Just to make sure you running everything in the virtual environment.

If your already doing that, I don’t know what’s going wrong.
@hel might though?

Good suggestion. I have been doing that every time I boot up.

Might be worth trying installing the library with the following commands?

git clone https://github.com/pimoroni/trilobot-python
cd trilobot-python
./install.sh --unstable

If you’re not using --unstable I think it might try and pull the previous version of the library from pip.

1 Like