본문 바로가기
Tech/Applications

Mac에서 pygame 라이브러리에서 에러 날 때

by 타이호 2020. 5. 7.
반응형

pygame으로 간단한 게임을 만들어 보는 것을 해보다가 Mac에서는 제대로 화면에 표시가 안되는 문제가 있어 해결방법을 공유한다.

 

1. 문제점

Mac Catalina 10.15.4에서 python3로 설치된 pygame(1.9.6)에서 백그라운드 이미지를 로드 했지만 이미지가 로드 되지 않고 빈 화면만 나오는 문제

# load backgroud image
backgroud = pygame.image.load("/Users/alex/background.png")

# event loop
running = True 
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    #screen.fill((0,0,255))        
    screen.blit(backgroud, (0,0))

2. 해결 방법

# 기존 설치된 pygame 삭제
$ pip uninstall pygame
# 혹은 pip3 uninstall pygame

# Dependency 설치
$ brew install sdl2 sdl2_gfx sdl2_image sdl2_mixer sdl2_net sdl2_ttf
$ brew install pkgconfig

# virtualenv 환경일 경우
$ cd .venv/lib/python3.7/site-packages/

# pygame 1.9.6버전 다운
$ git clone -b 1.9.6 https://github.com/pygame/pygame.git --single-branch

$ cd pygame/

$ python setup.py -config -auto -sdl2 
# 혹은 python setup.py --config --auto --sdl2

$ python setup.py install

 

3. 수정 후 다시 실행

반응형