You are not logged in.

#1 2017-11-17 04:19:31

JenDahm
Member
Registered: 2017-11-17
Posts: 2

[wxpython] 'Pycairo_CAPI' object has no attribute 'Context_FromContext

I recently installed pyspread, a spreadsheet program, from the AUR. When I start it up, the table isn't drawn at all. On the console, I get the following error repeatedly:

Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/pyspread/src/gui/_grid_renderer.py", line 293, in Draw
    grid._view_frozen)
  File "/usr/lib/python2.7/site-packages/pyspread/src/gui/_grid_renderer.py", line 248, in _get_cairo_bmp
    context = wx.lib.wxcairo.ContextFromDC(mdc)
  File "/usr/lib/python2.7/site-packages/wx-3.0-gtk2/wx/lib/wxcairo.py", line 137, in ContextFromDC
    ctx = pycairoAPI.Context_FromContext(ctxptr, pycairoAPI.Context_Type, None)
AttributeError: 'Pycairo_CAPI' object has no attribute 'Context_FromContext'

It looks to be an issue with wxpython based on the traceback, but the only things I can find only about it are from 2011 and reference issues people had with ROS. I've looked at Ubuntu's Artful repository to see if they have any relevant patches, but I couldn't find anything useful in either python-wxgtk3.0 (their equivalent to our wxpython) or python-cairo (their equivalent to our python2-cairo).

Bug FS#26770 references the exact same line of code that I'm breaking on with the exact same error, but the user encountered the issue with ROS. The issue was marked 'fixed' and closed without comment. I'm considering requesting that the bug be reopened since it looks like the same problem I'm having.

In addition to the requirements listed on the AUR page, I needed to install pygtk (depends on python2-cairo) and pango for pyspread to start up.

Has anyone else encounted this error? Is there any other relevant information I should post?

EDIT: For reference, here are the versions of wxpython and python2-cairo I have installed:

  • wxpython: 3.0.2.0-3

  • python2-cairo: 1.15.4-1

Last edited by JenDahm (2017-11-19 21:21:52)

Offline

#2 2017-11-19 21:19:20

JenDahm
Member
Registered: 2017-11-17
Posts: 2

Re: [wxpython] 'Pycairo_CAPI' object has no attribute 'Context_FromContext

I've done some more digging. Using the patch file provided with the bug report I mentioned, I found the file where Pycairo_CAPI is defined. This file is at "wx-3.0-gtk2/wx/lib/wxcairo.py" in the python2.7 package folder (on my disk at "/usr/lib/python2.7/site-packages"). It looks like the fields of the python object are defined based on the version of cairo installed. Specifically, the relevant lines are:

import cairo
# ...
class Pycairo_CAPI(ctypes.Structure):
    if cairo.version_info < (1,8):  # This structure is known good with pycairo 1.6.4
        # field declarations
    elif cairo.version_info < (1,9) or cairo.version_info == (1,10,8):
        # field declarations
    elif cairo.version_info < (1,11):
        # field declarations
# end

Opening up a python2 interactive instance, I typed in a few lines and got the following:

>>> import cairo
>>> cairo.version_info
(1, 15, 4)
>>> cairo.version_info < (1,8)
False
>>> cairo.version_info < (1,9) or cairo.version_info == (1,10,8)
False
>>> cairo.version_info < (1,11)
False

So it looks like the Pycairo_CAPI has no fields defined at all for the current version of pycairo! In fact, pycairo has updated several times since version 1.10, which was released in 2011. I'm going to try to patch this file with the latest CAPI format to see if that fixes the problem. If it does, I'll submit the patch upstream to wxpython.

Offline

#3 2017-12-17 18:14:00

J4ke
Member
Registered: 2017-12-10
Posts: 6

Re: [wxpython] 'Pycairo_CAPI' object has no attribute 'Context_FromContext

Offline

Board footer

Powered by FluxBB