Error With a program using pygame

Was using a book to learn a bit of Python. Trying out one of the programs in it returns an error. Have tried checking over the code and I can’t fire out what Im botching up. Would appreciate any help with this matter. Also I’m using PyCharm to edit the program.

import sys

import pyjama

class AlienInvasion:

        def _init_(self):

            self.screen = pygame.display.set_mode((1200,800))
            pygame.display.set_caption("Alien Attack)

        def run_game(self):
            while True:
                # Watch for keyboard and mouse events.
                for event in pygame.event.get():
                    if event.type == pygame.QUIT:


if __name__ == '__main__':
    ai = AlienInvasion()

I get the following error when running this.

pygame 2.4.0 (SDL 2.26.4, Python 3.11.2)
Hello from the pygame community.
Traceback (most recent call last):
  File "/Users/bijumathew/PycharmProjects/AchusGame/", line 22, in <module>
  File "/Users/bijumathew/PycharmProjects/AchusGame/", line 14, in run_game
    for event in pygame.event.get():
pygame.error: video system not initialized

Process finished with exit code 1

Would appreciate any help with this.

That doesn’t seem to be the code you actually ran, since what you posted has a SyntaxError and wouldn’t actually run at all ("Alien Attack is missing a closing quote mark), but the issue you’re actually looking for is that you have _init_ instead of __init__.

Also, you never actually import pygame.


I apologise for the delay. I’m sad I didn’t recognise the init portion. Changing that fixed the problem. About the typos I initially copied everything to an another program and typed out my message before posting here. The output was copied from pycharm though.

Either way changing the inti line fixed my problem. Thanks much.