Making the Automation HAT Mini output example portable

I’m working through the samples from the subject board. I moved the output.py example into my project python folder and it failed with this error:

Traceback (most recent call last):
File “/usr/lib/cgi-bin/output.py”, line 78, in
draw_states(automationhat.output())
File “/usr/lib/cgi-bin/output.py”, line 29, in draw_states
image = Image.open(“images/outputs-blank.jpg”)
File “/usr/lib/python3/dist-packages/PIL/Image.py”, line 2904, in open
fp = builtins.open(filename, “rb”)

I found that the output.py program had a relative link in line 31. I replaced this line

  "images/outputs-blank.jpg")

with this line

  "/home/pi/Pimoroni/automationhat/examples/hat-mini/images/outputs-blank.jpg")

And it now works. Hope that helps someone… or perhaps me in the future!

The other way to do it is to copy the images folder to the same folder you put output.py in.
It “should work”, I’ve hit similar snags with Enviro+ code that looks for icons. Moving the icons folder with the example file fixes it for me.

That’s true! Probably a good idea in the long term, but for those taking things step by step it might be helpful.

True enough, there’s usually more than one way to get things working the way you want.

For me, I run modified Enviro code on a couple of different builds. And don’t own or use an Enviro or Enviro+. They are equivalent setups with Breakout Garden stuff. I don’t ever run the Enviro Installer. I just copied the examples and what ever else I needed from the Enviro repository. And run the separate installers for the breakouts I’m using, SPI LCD, BME280, etc.