본문 바로가기

프로그래밍/Python

파이선 pycairo 에서 context 읽지 못하는 오류

728x90
반응형

파이선 pycairo 에서 context 읽지 못하는 오류

Cairo 는 오픈소스 2D 그래픽 라이브러리 이다. python 환경을 위해 pycairo 라는 패키지를 제공한다. cairo.Context 객체를 통해 간단한 그림을 그리거나, 글자를 작성할 수 있다.

테스트버전

  • Python 3.8.10
  • pycairo 1.23.0
  • libcairo-gobject2 1.16.0-4

Context 참조오류

cairo.Context 를 사용하기 위해서는 python3-gi-cairo 를 반드시 설치해야한다. 만약 python3-gi-cairo 가 설치되어 있지 않으면 다음과 같은 에러가 발생한다.

File "main.py", line 57, in on_draw
    context.rectangle(900, 500, 120, 80)
AttributeError: 'gobject.GBoxed' object has no attribute 'rectangle'

Context 참조오류 해결

pycairo 사용을 위해 아래 패키지를 설치한다.

sudo apt-get install python3-gi-cairo

참고자료

https://pycairo.readthedocs.io/en/latest/

 

Overview — Pycairo documentation

Pycairo is a Python module providing bindings for the cairo graphics library. It depends on cairo >= 1.15.10 and works with Python 3.7+ and PyPy3. Pycairo, including this documentation, is licensed under the LGPL-2.1-only OR MPL-1.1. The Pycairo bindings a

pycairo.readthedocs.io

반응형