B4J Question Probleme Execute Python script with from B4J

Michael1968

Active Member
Licensed User
Longtime User
Hi all...
I have a problem with running a python script on a raspberry pi with jshell lib.

I call the script with:
B4J:
sh.Initialize("sh", "python",Array As String("blinkatest.py",Null))

i get this error:
Waiting for debugger to connect...
Program started.
Error: Traceback (most recent call last):
File "blinkatest.py", line 2, in <module>
import board
ModuleNotFoundError: No module named 'board'

the script is a python script with adafruit blinka lib.
python:
import sys
import board
import digitalio
import busio

print("Hello blinka!")

# Try to great a Digital input
pin = digitalio.DigitalInOut(board.D4)
print("Digital IO ok!")

# Try to create an I2C device
i2c = busio.I2C(board.SCL, board.SDA)
print("I2C ok!")

# Try to create an SPI device
spi = busio.SPI(board.SCLK, board.MOSI, board.MISO)
print("SPI ok!")

print("done!")
print("test")

if i start the script in a raspberry pi terminal
the script runs fine.

if i start a "normal" script from b4j...everything is fine

any idea ??

best regards
Michael
 
Last edited:

Michael1968

Active Member
Licensed User
Longtime User
ok...it seem to work if i execute the programm direct on the pi.

there must be a problem with B4J-Bridge and debug mode.
 
Upvote 0

xulihang

Active Member
Licensed User
Longtime User
Is board a folder which blinkatest.py sits with?

I came across this problem as well and I ended up adding the workdir into the sys path with the following Python code.

Python:
sys.path.append(os.getcwd())
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
 
Last edited:
Upvote 0
Top