Skip to content
Advertisement

PyCharm can’t find reference in PyGame __init__.py?

OK, I’m very new to coding, and I am just learning Python. I figured I would start with some basic Pygame exercises to try to have something to program.

I’ve installed Python 3.4.3 and PyCharm. I also installed the Pygame executable “pygame-1.9.2a0-hg_5974ff8dae3c+.win32-py3.4.msi” from here: https://bitbucket.org/pygame/pygame/downloads

I ran the Pygame installer, and it seemed to complete without visible issues, though there were no obvious signs like new shortcuts on my desktop.

I then went here to try some basic test code involving Pygame: http://pythonprogramming.net/pygame-python-3-part-1-intro/

So I copied the code from that example into my Pycharm, and ran it. It seems to create a blank Pycharm windows alright, but the PyCharm Code Inspector is giving me several warnings, and I really want to know why I am getting these warnings.

The first Pycharm warning is from line 5, “Cannot find reference ‘init’ in ‘__init__.py’ The next warning is line 16, “Cannot find reference ‘QUIT’ in ‘__init__.py’ The third and final warning is line 24, “Cannot find reference ‘quit’ in ‘__init__.py

Why can’t it find these references? What’s wrong?

The code itself I paste below:

#! /usr/bin/python

import pygame

pygame.init()

gameDisplay = pygame.display.set_mode((800, 600))
pygame.display.set_caption('A bit Racey')
clock = pygame.time.Clock()

crashed = False

while not crashed:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            crashed = True

        print(event)

    pygame.display.update()
    clock.tick(60)

pygame.quit()
quit()

Advertisement

Answer

This will work for you with no errors… import the system and do a system exit instead

#! /usr/bin/python

import pygame
import sys

pygame.init()

gameDisplay = pygame.display.set_mode((800, 600))
pygame.display.set_caption('A bit Racey')
clock = pygame.time.Clock()

crashed = False

while not crashed:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            crashed = True

        print(event)

    pygame.display.update()
    clock.tick(60)

pygame.quit()
sys.exit()

enter image description here

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement