I recently bought a new macbook and I've been trying endlessly to get pygame
to work, but haven't succeeded yet. I'm getting pretty desperate and I could really use some help.
I've installed pygame 1.9.4
and even though I don't get any error messages when running pygame
code, it won't show me anything but a blank screen. I'm using the following code to test it:
import pygame pygame.init() screen = pygame.display.set_mode((800,600)) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: quit() screen.fill((255,0,0)) pygame.display.update() pygame.quit()
On my old macbook the test code gives me a red screen as expected. Both macbooks are running python 2.7.10
.
Does anyone have any idea what I'm doing wrong? I think I installed pygame
exactly like I did on my old macbook and the only difference seems to be the operating system.
edit 1: I write the script in Sublime Text and run the program in Terminal. Screenshot
edit 2: I got pygame working again by downgrading my operating system to macOS High Sierra.
Steps to make a pygame window: Import pygame module. Create a pygame window object using pygame. display. set_mode() method.
Setting the display mode is handled with the function pygame. display. set_mode((width, height), flags, depth) Initialize a window or screen for display. The only required argument in this function is a sequence containing the width and height of the new display mode.
To test if PyGame has been installed on your Mac, open IDLE by typing IDLE in your Spotlight search bar. Then type import pygame as shown in the image. If you do not see any error, it means that PyGame has been successfully installed on your Mac.
Tested and works on macOS 10.15 Catalina
, Python 3.7.5
, PyGame 2.0.0
(pre-release as of this writing) and PyGame 1.9.6
(stable as of this writing).
Initially you need to decide if you want a stable release or a pre-release (unstable). If you decide to use the latest (and possibly pre-release/unstable) then just ignore the first step ("1. Find the latest stable release version") and use master
branch at step 4 of the second step ("2. Install PyGame from source").
Go to PyGame's GitHub page here:
As you can see as of this writing the latest stable release is 1.9.6
so we hold this tag name for later.
brew install sdl2 sdl2_gfx sdl2_image sdl2_mixer sdl2_net sdl2_ttf
. This requires homebrew.site-packages
: cd ~/.virtualenvs/myvirtualenv/lib/python3.X/site-packages
where ~/.virtualenvs/myvirtualenv
is the path to your virtual environment and python3.X
is the version of your Python. /usr/local/lib/python3.X/site-packages
where python3.X
is the version of your Python.pip uninstall pygame
(if a pygame
directory exists in site-packages
then remove it: rm -rf pygame*
)git clone https://github.com/pygame/pygame.git
for the latest (possibly not stable version).git clone -b 1.9.6 https://github.com/pygame/pygame.git --single-branch
for the latest (1.9.6
is the tag name of the latest stable release, as of this writing, see "Find the latest stable release version above")pygame
directory: cd pygame
.python setup.py --config --auto --sdl2
. python setup.py -config -auto -sdl2
. python setup.py --config --auto --sdl2
to python3 setup.py --config --auto --sdl2
.python setup.py install
(it will take a while). python setup.py --config --auto --sdl2
to python3 setup.py --config --auto --sdl2
.Now PyGame should work as expected on macOS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With