简体   繁体   中英

'CompiledFFI' instead of 'FFI' when including 'cairocffi'

I want to use Pango with the Cairo backend in Python 3. I chose 'cairocffi' for reasons that are not relevant here. I am trying to run the example in the documentation . It calls Pango through CFFI. The very beginning of the example

import cairocffi
import cffi
ffi = cffi.FFI()
ffi.include(cairocffi.ffi)

gives the following error.

  File "/usr/lib/python3.6/site-packages/cffi/api.py", line 494, in include
    type(ffi_to_include).__name__,))
TypeError: ffi.include() expects an argument that is also of type cffi.FFI, not 'CompiledFFI'

I have been trying to understand the CFFI documentation, but I am completely lost. First, where is CompiledFFI documented? Second, why do not I see include , cdef , set_source methods in the FFI interface ? And the main question is, what am I doing wrong?

It looks like cairocffi was updated to use the more modern way of using cffi, but this makes the example outdated. You should ask the cairocffi authors to update the example.

ffi.include() is documented here: http://cffi.readthedocs.io/en/latest/cdef.html#ffi-ffibuilder-include-combining-multiple-cffi-interfaces . The confusion comes from the fact that in the modern equivalent, the ffi object would be called ffibuilder instead in that example (which would be structured differently).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM