Python3: Namespace AppIndicator3 not available

OS: Kubuntu 18.04

I have a Python program (program.py) that has this at the beginning:

import shlex
import sys
import notify2
import os
import gi

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk

gi.require_version("AppIndicator3", "0.1")
from gi.repository import AppIndicator3

When I run it, this is what happens:

$ python3 /path/to/program.py 
Traceback (most recent call last):
  File "/path/to/program.py", line 34, in <module>
    gi.require_version('AppIndicator3', '0.1')
  File "/home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.5/lib/python3.8/site-packages/gi/__init__.py", line 129, in require_version
    raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace AppIndicator3 not available

The following shows the Python modules I have:

$ brew uninstall python3
Error: Refusing to uninstall /home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.5
because it is required by at-spi2-atk, at-spi2-core, atk, cairo, docbook, docbook-xsl, enchant, freeglut, gdk-pixbuf, glib, glu, gobject-introspection, graphviz, gsettings-desktop-schemas, gtk+3, gtksourceview3, gts, harfbuzz, httpd, imagemagick, itstool, libepoxy, libheif, liblqr, libva-internal, libxml2, libxslt, llvm, mesa, meson, netpbm, pango, php, php-cs-fixer, pipenv, py3cairo, pyenv, pygobject3, shared-mime-info, vala, wayland and xmlto, which are currently installed.
You can override this and force removal with:
  brew uninstall --ignore-dependencies python3

Any clue to what might be causing this?

You’re not showing the python modules you have. Pip freeze would show those.

I think you need to update the gi python package.

$ pip3 freeze
dbus-python==1.2.16
docutils==0.16
formiko==1.4.3
libxml2-python==2.9.10
meson==0.55.1
notify2==0.3.1
pycairo==1.19.1
PyGObject==3.36.1

$ brew install gobject-introspection
Warning: gobject-introspection 1.64.1_2 is already installed and up-to-date
To reinstall 1.64.1_2, run `brew reinstall gobject-introspection`

https://pygobject.readthedocs.io/en/latest/getting_started.html would suggest (reading the homebrew/macOS version) that this is not the package you need to install for import gi to work.

This is also all really specific to pygobject and I think it will be better to contact that project to help you debug, since I don’t see anything that could point to this being a homebrew issue.

@SMillerDev thanks. Will do.