Bookworm SM16relind - Problems Thonny - import fails

macmack5

New member
16 relay board

I can run the C test program - all LED's light in sequence. I can run python in my virtual environment from the command line and import SM16relind works. I can't get it to import in Thonny. I have referenced the python3.11 program correctly. What am I missing?
 

alexburcea

Moderator
Staff member
It might be an idea to install the library directly without the virtual environment. Open a terminal, browse to the 16relind-rpi/python/ folder, and then run "sudo python setup.py install". This should install the library for the Python interpreter Thonny uses.
 

macmack5

New member
In the latest OS for R Pi you are forced to use the virtual environment. For the long explanation:

https://peps.python.org/pep-0668/

The solution for Thonney development environment users:

(1) Create the virtual environment in thonney:
make a new, clean folder somewhere
switch to classic mode
tools / options / interpreter
(I set python3.11 as executable, too)
"New virtual environment"
select the new, clean folder you made in the first step
(2) command window
cd "new folder"
source bin/activate
cd bin
pip install SM16relind (or pip3.11 install SM16relind)
(3) import SM16relind
rel = SM16relind.SM16relind(0)
rel.set(1,1)
print(rel.get_all())
(4) Should return 1

Using the pip in the virtual environment is the key. Either use path, or change to the bin folder.
 
Top