Leader only image bug - HardwarePWM not found

Dear Pioreactor team,

I am using leader only image file with the most recent update on the leader, and I got the following bug:

Running pio --help in the leader command line results with NameError: name ‘HardwarePWM’ is not defined. The error log for pio --help:

Traceback (most recent call last):
  File "/usr/local/bin/pio", line 8, in <module>
    sys.exit(pio())
             ^^^^^
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 1077, in main
    with self.make_context(prog_name, args, **extra) as ctx:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 943, in make_context
    self.parse_args(ctx, args)
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 1644, in parse_args
    rest = super().parse_args(ctx, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 1408, in parse_args
    value, args = param.handle_parse_result(ctx, opts, args)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 2400, in handle_parse_result
    value = self.process_value(ctx, value)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 2362, in process_value
    value = self.callback(ctx, self, value)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 1300, in show_help
    echo(ctx.get_help(), color=ctx.color)
         ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 704, in get_help
    return self.command.get_help(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 1325, in get_help
    self.format_help(ctx, formatter)
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 1358, in format_help
    self.format_options(ctx, formatter)
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 1564, in format_options
    self.format_commands(ctx, formatter)
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 1617, in format_commands
    cmd = self.get_command(ctx, subcommand)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/pioreactor/cli/lazy_group.py", line 25, in get_command
    return self._lazy_load(cmd_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/pioreactor/cli/lazy_group.py", line 33, in _lazy_load
    mod = importlib.import_module(modname)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/usr/local/lib/python3.11/dist-packages/pioreactor/cli/run.py", line 7, in <module>
    from pioreactor import actions
  File "/usr/local/lib/python3.11/dist-packages/pioreactor/actions/__init__.py", line 6, in <module>
    from pioreactor.actions import od_calibration
  File "/usr/local/lib/python3.11/dist-packages/pioreactor/actions/od_calibration.py", line 25, in <module>
    from pioreactor.background_jobs.od_reading import start_od_reading
  File "/usr/local/lib/python3.11/dist-packages/pioreactor/background_jobs/__init__.py", line 6, in <module>
    from pioreactor.automations import *  # noqa: F401,F403
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/pioreactor/automations/__init__.py", line 4, in <module>
    from . import dosing
  File "/usr/local/lib/python3.11/dist-packages/pioreactor/automations/dosing/__init__.py", line 9, in <module>
    from .chemostat import Chemostat
  File "/usr/local/lib/python3.11/dist-packages/pioreactor/automations/dosing/chemostat.py", line 5, in <module>
    from pioreactor.automations.dosing.base import DosingAutomationJob
  File "/usr/local/lib/python3.11/dist-packages/pioreactor/automations/dosing/base.py", line 19, in <module>
    from pioreactor.actions.pump import add_alt_media
  File "/usr/local/lib/python3.11/dist-packages/pioreactor/actions/pump.py", line 26, in <module>
    from pioreactor.utils.pwm import PWM
  File "/usr/local/lib/python3.11/dist-packages/pioreactor/utils/pwm.py", line 38, in <module>
    class HardwarePWMOutputDevice(HardwarePWM):
                                  ^^^^^^^^^^^

In the shared config.ini [PWM] section, I have the same structure as you described in your Cluster topology text. In other words:

[PWM]
# map the PWM channels to externals.
# hardware PWM are available on channels 2 & 4.
1=stirring
2=media
3=alt_media
4=waste
5=heating

However, perhaps the issue is more than that and I could not track it well so I am sharing the issue here. Just to be clear, I do not get this error when I run:

  1. pios --help in the command line with the leader only image
  2. pio --help in the command line with the leader-worker image

Hi @sharknaro,

hm, not sure why this started with the most recent update. Are you connected to the internet? If so, here’s an fix:

sudo pip install rpi-hardware-pwm

If you don’t have internet, I can provide instructions to upload the file to fix. Are you blocked by this bug?


There might be other import bugs even after this one is resolved. Generally, you can “solve” this by installing the missing libraries: pioreactor/setup.py at master · Pioreactor/pioreactor · GitHub

Ex:

sudo pip install adafruit-circuitpython-ads1x15==2.2.23
sudo pip install DAC43608==0.2.7

and so on

1 Like

For other users who experience this but don’t have internet:

  1. Download this zip file locally.

  2. Connect to your Pioreactor cluster’s network. On your command line, we’ll upload this zip file to your leader. For my Mac computer, uploading to my leader leader.local, this looks like:

    scp ~/Downloads/wheels_24.5.31.zip pioreactor@leader.local:~/
    
  3. SSH into your leader,

     ssh pioreactor@leader.local
    

    you should see this zip file if you do an ls.

  4. unzip the zip file to a folder:

    unzip wheels_24.5.31.zip -d wheels/
    
  5. And install everything you need:

    sudo pip install --no-index --find-links=wheels/ rpi-hardware-pwm plotext TMP1075 DAC43608 adafruit-circuitpython-ads1x15 
    
  6. Restart the Pioreactor

1 Like

Hey Cameron, I am currently having this issue so my experiment is not being recorded… I tried this fix and it does not seem to work. it still clears all data from the overview screen everytime I leave the page

Hi @Stkral,

Hm, did all the steps look like they completed successfully, and you restarted the Pioreactor after completing the steps?

Can you SSH in again and try running:

pio run mqtt_to_db_streaming

Any errors when you run that?

NameError: name ‘HardwarePWM’ is not defined. I get this error.

I am using a setup with an external raspberry Pi that is a leader only

Right, and did you try either

or

(if you have internet access on the Pioreactor leader)

Another solution, albeit slightly more brute force, is to reflash with the latest image (released this past Monday, June 10) which should have the fix in.

Thanks for the quick reply!

I did this method you described and that didn’t seem to work:

For other users who experience this but don’t have internet: Download this [zip file]

Then I also ran the commands you suggested to sharknaro.
sudo pip install rpi-hardware-pwm
sudo pip install adafruit-circuitpython-ads1x15==2.2.23
sudo pip install DAC43608==0.2.7

And now it works. Not sure what did it but thanks again :slight_smile:

And now it works. Not sure what did it but thanks again :slight_smile:

yay computers! haha we fixed this bug so future users won’t hit is, so I’m pretty okay with this result

1 Like

Hi @Stkral,

Hsppy to here that you mansged to fix it! When I had this issue running just sudo pip install rpi-hardware-pwm was enough to fix the issue, and it also matches with the error statement, so I would say this package wad the trick with this specific case :)).

1 Like