I managed to install Pygame on Big Sur. but when I use modules within it, it fails out. I have a new M1 laptop running Big Sur (11.4) and I installed homebrew, python3, pip3, and then Pygame.
If I run this skeleton:
import sys
import pygame
from pygame.locals import *
pygame.init()
fps = 60
fpsClock = pygame.time.Clock()
width, height = 640, 480
screen = pygame.display.set_mode((width, height))
is_blue = True
# Game loop.
while True:
screen.fill((0, 0, 0))
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
is_blue = not is_blue
# Update.
# Draw.
if is_blue: color = (0, 128, 255)
else: color = (255, 100, 0)
pygame.draw.rect(screen, color, pygame.Rect(30, 30, 60, 60))
pygame.display.flip()
fpsClock.tick(fps)
it works fine. But if I add this line just after init:
myfont1 = pygame.font.SysFont("Comic Sans MS", 20)
I get the following error message:
pygame 2.0.1 (SDL 2.0.14, Python 3.9.5)
Hello from the pygame community. https://www.pygame.org/contribute.html
/Users/lmiratrix/PycharmProjects/pythonProject1/main_v2.py:8: RuntimeWarning: use font: cannot import name 'Font' from partially initialized module 'pygame.font' (most likely due to a circular import) (/opt/homebrew/lib/python3.9/site-packages/pygame/font.py)
(ImportError: cannot import name 'Font' from partially initialized module 'pygame.font' (most likely due to a circular import) (/opt/homebrew/lib/python3.9/site-packages/pygame/font.py))
myfont1 = pygame.font.SysFont("Comic Sans MS", 20)
Traceback (most recent call last):
File "/Users/lmiratrix/PycharmProjects/pythonProject1/main_v2.py", line 8, in <module>
myfont1 = pygame.font.SysFont("Comic Sans MS", 20)
File "/opt/homebrew/lib/python3.9/site-packages/pygame/__init__.py", line 59, in __getattr__
raise NotImplementedError(missing_msg)
NotImplementedError: font module not available (ImportError: cannot import name 'Font' from partially initialized module 'pygame.font' (most likely due to a circular import) (/opt/homebrew/lib/python3.9/site-packages/pygame/font.py))
I am not sure how to proceed (and I am hopeful this is not the cosmos telling me comic sans is just a no go! :-) )
Background: I really struggled to get Pygame to work in the first place, ending up with strange error messages in PyCharm. I shifted to terminal after figuring out that homebrew is installing everything, including a fresh python3, in /opt/homebrew/ rather than /usr/local/bin or similar, but PyCharm was only finding python installations in /usr/bin for a bit. I tried to uninstall Pygame and then used spotlight to delete all the various Pygame files from the computer, reinstalled everything, and then landed here with a partial success.