1

I am an enthusiast fairly new to working with python. It has been a week since I installed Pygame, and after numerous attempts, I still can’t get the Pygame window to launch or open when I run any of my programs. I have watched as many tutorials as I can, as well as reading all the articles on similar issues I could find. I have copied all of the solutions I found on other websites and the problem still persists. Stranger nonetheless, is the fact that the IDE I am using (Pycharm) rarely outputs an error message, and instead simply continues running but never launches the Pygame window. I am using Pycharm with python 3.8.1 and Pygame version 1.9.6 installed. I am using a Mac with High Sierra.

I greatly appreciate any help anyone can provide.

The below code only outputs the pygame version and the "welcome" message, but continues to run without the window ever launching.

import pygame

    (width, height) = (1000, 700)
    screen=pygame.display.set_mode((width, height))
    pygame.display.update()
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

The next code block has the exact same output as the one above.

    # courtesy of Ene Uran www.daniweb.com

import pygame as pg

pg.init()

screen = pg.display.set_mode((400, 300))

pg.display.set_caption('Draw/fill rectangles using pygame')

white = 0xFFFFFF
red = 0xFF0000
green = 0x00FF00
blue = 0x0000FF
yellow = 0xFFFF00

screen.fill(white, (250, 50, 77, 33))

screen.fill(red, (30, 20, 70, 120))
screen.fill(red, (140, 70, 90, 80))
screen.fill(green, (150, 80, 70, 60))
screen.fill(yellow, (200, 170, 150, 60))
screen.fill(blue, (70, 200, 100, 70))

pg.display.update()


while True:
    for event in pg.event.get():
        if event.type == pg.QUIT:
            raise SystemExit

The following code block also returns the same output:

import pygame
from pygame.locals import *

pygame.init()
screen = pygame.display.set_mode((640, 480), 0, 24)
#clock = pygame.time.Clock()

#font = pygame.font.Font(None, 32)

cycles = 0
while True:
    pygame.event.get()
    screen.fill(0)
#    text = font.render('Cycles : %d' % cycles, True, (255, 255, 255))
#    screen.blit(text, (100, 100))

    cycles += 1

    pygame.display.update()

This code^^ is from the original stack overflow forum for this issue: Pygame window not responding after a few seconds

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
K2SO
  • 3
  • 2
  • 1
    Do you get better results running without PyCharm? – Kingsley Jan 27 '20 at 22:41
  • All examples seem fine in Python 3.6 x64, Pygame 1.9.6, Pycharm 2019.3 on Windows 10 – Thomas Weller Jan 27 '20 at 22:46
  • No - Believe it or not, I can't get Pygame to import into any IDE other than Pycharm so far. – K2SO Jan 27 '20 at 22:48
  • If you have a venv in Pycharm, you should be able to run it from console as well – Thomas Weller Jan 27 '20 at 22:49
  • 1
    Sounds like you need an earlier version of python and pygame. https://github.com/pygame/pygame/issues/1554 – tgikal Jan 27 '20 at 22:49
  • @tgikal: "1.9.6 is somewhat broken on current Mac, sorry.", so downgrading Python does not seem to help – Thomas Weller Jan 27 '20 at 22:51
  • Yeah, I have noticed that the results of these tests heavily differ from Mac to Windows users. It could simply be a coincidence, but I doubt it. – K2SO Jan 27 '20 at 22:51
  • I just tried running it from the console within Pycharm, and got the same result. – K2SO Jan 27 '20 at 22:53
  • Seems like python 3.7.0, and pygame 1.9.4 worked for many mac users. – tgikal Jan 27 '20 at 22:57
  • Does anyone have a mac that they can test the code on? I want to see if it is just a problem with the IDE. – K2SO Jan 27 '20 at 22:58
  • Try a dev version? https://github.com/pygame/pygame/issues/555#issuecomment-541237897 `pip3 install pygame==2.0.0.dev7` should be the absolute latest release. – tgikal Jan 27 '20 at 22:58
  • Ok thanks - Ill give it a try. – K2SO Jan 27 '20 at 23:02
  • @tgikal: I just tried pip3 install pygame==2.0.0.dev7 and I got a "no matching distribution" error. – K2SO Jan 27 '20 at 23:06
  • @K2SO Looks like 7 is still developing, try 6? `pip3 install pygame==2.0.0.dev6` or `pip3 install pygame==2.0.0.dev4` Apparently they hate odd numbers... There are definitely wheels for 6 https://github.com/pygame/pygame/releases/tag/2.0.0.dev6 – tgikal Jan 27 '20 at 23:09
  • @tgikal - Ok, dev6 installed. Now I will rerun the program within Pycharm. – K2SO Jan 27 '20 at 23:14
  • 1
    @tgikal - Brilliant! It worked. Thank you so much for the help. – K2SO Jan 27 '20 at 23:18
  • @K2SO Hopefully they'll have most the bugs worked out with the official 2.0.0 release, I see there are still quite a few for mac os even in 2.0.0.dev6, so just be aware that it is only semi-working and check the github page for issues. https://github.com/pygame/pygame/issues – tgikal Jan 27 '20 at 23:23
  • @tgikal - Got it. Thanks again. – K2SO Jan 27 '20 at 23:47

1 Answers1

1

pygame 1.9.6 does not work with python 3.8.1 on mac os.

See https://github.com/pygame/pygame/issues/555 for details.

Try installing a pygame development version such as pygame 2.0.0.dev6:

pip3 install pygame==2.0.0.dev6

But watch out for bugs.

tgikal
  • 1,667
  • 1
  • 13
  • 27