問題描述:
初次運(yùn)行程序(來自《Python Cash Course》)
import sys
import pygame
def run_game():
# Initialize game and create a screen object.
pygame.init()
screen = pygame.display.set_mode((1200, 800))
pygame.display.set_caption("Alien Invasion")
# Set the background color.
bg_color = (230, 230, 230)
# Start the main loop for the game.
while True:
# Watch for keyboard and mouse events.
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
# Make the most recently drawn screen visible.
pygame.display.flip()
run_game()
出現(xiàn)空白頁面,沒有顏色???
發(fā)現(xiàn)很多人遇到內(nèi)樣的問題:
Pygame not compatible with MacOS Mojave #555
從上面這個(gè)貼子中,有建議是下載Miniconda缠沈,但是我覺得有點(diǎn)麻煩????
后來發(fā)現(xiàn)有個(gè)回復(fù)是:從官網(wǎng)下載最新Python包
- 從官網(wǎng)下載安裝包:Python.org
我下載的是macOS 64-bit installer - 下載完成后摩渺,安裝简烤。安裝成功后試試 python3 --version
$ python3 --version
Python 3.7.2
- 這時(shí),重新運(yùn)行程序摇幻,發(fā)現(xiàn)提示Pygame不存在了横侦。再安裝一次
$ pip3 install pygame
重新運(yùn)行程序,成功了绰姻!