Home > Blockchain >  Pyinstaller not building the cairo.Context properly
Pyinstaller not building the cairo.Context properly

Time:10-11

NOTE: I've edited this description and title to include new information during the debugging process.

I have a python application that needs to be converted to an executable. The application draws graphics using the python-gi-cairo package, among others.

The following is an error message in the terminal window, after launching the application:

TypeError: Couldn't find foreign struct converter for 'cairo.Context'

I've already posted separately about making a minimal drawing app that I can test pyinstaller parameters with. Here is a link to that post:

https://stackoverflow.com/questions/73981704/missing-dependency-after-running-pyinstaller?noredirect=1#comment130629339_73981704

here is the evms.spec file:

# -*- mode: python ; coding: utf-8 -*-


block_cipher = None


a = Analysis(
    ['evms.py'],
    pathex=[],
    binaries=[],
    datas=[],
    hiddenimports=['matplotlib', 'python-gi-cairo'],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=block_cipher,
    noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

exe = EXE(
    pyz,
    a.scripts,
    a.binaries,
    a.zipfiles,
    a.datas,
    [],
    name='evms',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    upx_exclude=[],
    runtime_tmpdir=None,
    console=True,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
)

CodePudding user response:

It turned out there was a missing import statement, (import cairo) which when added, enabled the pyinstaller to build an executable that works great. I'm not sure why the .py version of the application was working without that import.

import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk as gtk
from gi.repository import Gdk as gdk
import cairo
from gi.repository import GLib
  • Related