1

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()
Victor
  • 3,669
  • 3
  • 37
  • 42
Sindyr
  • 1,277
  • 1
  • 11
  • 16
  • Your code is working correctly, the code you did is just one part of several to make a car game. It should display black screen with mouse events on it. You can ignore the pep8 and pycharm error on the undefined quit. In later step it will all be fine. – john taylor Aug 11 '15 at 22:23
  • 1
    I figured that was the case, but I am a little OCD. I need to track down why the error is happening or it will keep bothering me. Is it because the person who built the Pygame library didn't include something that Pycharm is expecting? If so, can I fix that somehow? Or is something deeper amiss, like maybe I installed the wrong version of Pygame, or it mis-installed somehow? Or possibly, everything is fine and this is a Pycharm bug. I need to positively identify what is causing this, because it's driving my OCD nutty. Thanks. – Sindyr Aug 11 '15 at 22:35
  • nope no bug, just OCD. you can read pep8 but dont over do it. At 2015 Pycon [Raymond Hettinger - Beyond PEP 8](https://www.youtube.com/watch?v=wf-BqAjZb8M) he talks about people over fixing pep8. – john taylor Aug 11 '15 at 22:57
  • Nevermind my comment here, for some reason your comment was cut off but know I see the whole sentence ;) Will consider. – Sindyr Aug 11 '15 at 23:02
  • 1
    OK, here's my main trouble, and it's (IMO) a bg one: If Pycharm's "Cannot find reference X in '__init__.py'" is a useless error or it's actually a helpful error. Let's assume that it's a useless error. That would indicate that I could inform Pycharm that it should never again trouble me with this kind of error in the future, and that wouldn't cause problems. But if that's the case, then why does Pycharm have it at all? It's hard to believe that being unable to find a reference isn't going to be important sooner or later. But if it is important, then why not here and now? I'm troubled. – Sindyr Aug 11 '15 at 23:14

1 Answers1

0

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

john taylor
  • 1,080
  • 15
  • 31
  • Thanks, I just entered that, and funnily enough, I get the same three warnings in the same three places. Weird! I have no idea why it cannot find references in ‘`__init__.py`’ – Sindyr Aug 12 '15 at 00:21
  • that's a separate error, from the quit thing. I think in PyCharm preferences you add a path to your active Python Interpreter and download the Python "site-packages" it will go away – john taylor Aug 12 '15 at 00:27
  • Unless it some error on the latest one. create a new project and new file without refactoring it maybe. – john taylor Aug 12 '15 at 00:35
  • you can test program in ide if no error you are good that looks to be a [unresolved pycharm error](http://stackoverflow.com/questions/23248017/cannot-find-reference-xxx-in-init-py-python-pycharm) that they know of – john taylor Aug 12 '15 at 00:44
  • I do not get that warning to replicate it to help you further. but your code is good. That is a pycharm error. I use sublime3 as a editor 99% of the time only use pycharm if fixing up someone stuff or it does work. – john taylor Aug 12 '15 at 00:48
  • ...and today when I load up my project and file NO ERRORS. lol. Maybe it had to re-index something, or maybe I needed to restart my PC for some reason before it saw those references... In any case, with no problem remaining, I guess we are all set. Thanks everyone! – Sindyr Aug 12 '15 at 15:57