Seeing No module named 'ops' with bash based charm

I utilize rust and execute that within bash hooks for all my charms… reason being I prefer the bash hook “workflow”… but obviously for advanced routines I leverage a rust CLI tool with some more advanced know how / logic … and all is working great on my side… BUT i did notice that the charm has some errors and I just wanted to draw attention to it incase it’s causing unknown problems in my model

Now I checked my charm… and indeed I have a requirements.txt with the ops pypi module wired in… just so when I pack charmcraft is happy… but is this a true problem with my bash charm? I don’t see anything going wrong but… wanted to checkin

assuming you’re in the charm root, you might need to prefix your python command with PYTHONPATH=lib:venv. The venv folder contains all packages that charmcraft should have packed for you.

To check:

  • that there is a /var/lib/juju/agents/unit-YOURAPP-0/charm/venv/ops folder with the ops package in it
  • that python knows how to reach that package (you might need to read up on importlib); I would try: sys.path.append("/var/lib/juju/agents/unit-YOURAPP-0/charm/venv/") and see if the import succeeds
1 Like