Fixing Broken Python GI Bindings | Generated by AI

Home 2025.10

Updated Diagnosis

Based on the new details, your Python 3.13.7 installation (likely manual or via PPA/source) has broken the system’s GObject Introspection (GI) bindings. The gi module’s _gi C extension is compiled for your distro’s default Python (probably 3.10 or 3.11, given the directories in /usr/lib/python), not 3.13. This causes the circular import error when gnome-terminal (a Python script) tries to load it. The multi-version setup in /usr/lib/python confirms this mismatch—system packages like python3-gi aren’t built for 3.13 yet (it’s too new for most distros as of 2025).

The UFW logs remain irrelevant noise.

The cleanest solution is to switch /usr/bin/python3 back to your distro’s default (e.g., 3.10), then reinstall GI bindings. This avoids hacks like copying .so files, which can cause inconsistencies.

  1. Identify and switch to the default Python version (use update-alternatives if configured; otherwise, manual symlink):
    # Check if alternatives are set up
    sudo update-alternatives --config python3
    
    • If it lists options, select the lowest priority one (usually the distro default, like 3.10).
    • If no alternatives (common on stock Ubuntu), manually revert:
      # Assuming default is 3.10 (common for Ubuntu 22.04; swap to 3.11 if that's your base)
      sudo rm /usr/bin/python3
      sudo ln -s /usr/bin/python3.10 /usr/bin/python3
      
    • Verify: python3 --version should now show 3.10.x (or your default).
  2. Reinstall GI and GNOME Terminal packages:
    sudo apt update
    sudo apt install --reinstall python3-gi gir1.2-glib-2.0 gnome-terminal
    
  3. Test:
    python3 -c "from gi.repository import GLib, Gio; print('GI OK')"
    gnome-terminal
    
    • If the Python test passes but terminal still fails, reset its config: dconf reset -f /org/gnome/terminal/.

If You Want to Keep Python 3.13

Prevention

If this doesn’t fix it, run ls -l /usr/bin/python* and dpkg -l | grep python3 | grep -E 'gi|default' and share the output.

gnome-terminal will not start after trying to install newer version of Python 3
ImportError: cannot import name ‘_gi’ from partially initialized module ‘gi’
Why won’t terminal open?


Back

x-ai/grok-4-fast:free

Donate