Python Forum

Full Version: pygame
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello,
Totally new to Python, learning with my son.
Can not get pygame to run. Here's the error that I'm getting:

Command "/usr/local/opt/python@2/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/px/j72ynrm54_56m1zqs_kzn8qh0000gn/T/pip-req-build-ZAEiwc/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/px/j72ynrm54_56m1zqs_kzn8qh0000gn/T/pip-record-xVwrjx/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/px/j72ynrm54_56m1zqs_kzn8qh0000gn/T/pip-req-build-ZAEiwc/

I followed these instructions from this website.
http://brysonpayne.com/2015/01/10/settin...-on-a-mac/

All worked until the final step, with error that appeared above.

Thanks in advance for your help.
D
The post you're using to install is three years old.
I'm wondering if the packages that you are installing are up to date.
I'm not an apple user, so kow nothing about brew.

I think a better way to do this is to install pip see: https://ahmadawais.com/install-pip-macos-os-x-python/
then use standard pip install:
pip install pygame
Thanks for the sharing. Followed through and installed as per website... however, when I tried to install pygame (punched in: sudo pip3 install hg+http://bitbucket.org/pygame/pygame) the same error came back. Thanks in advance for your help everyone!
use the command verbatim:
pip install pygame
Excellent! It worked... champion! Successfully installed. pygame 1.9.3

Okay one last request...

Punched in the following:

python3
>>> import pygame

I get the following message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pyjama'

Thanks again!
do you have two versions of python installed?
If so, you may have installed pygame in the wrong one.
This is a very likely possibility.
To test, go to command line and type:
pip -V
if the right python, type:
pip list
for a list of installed packages
(Apr-24-2018, 10:58 AM)Dobrasz Wrote: [ -> ]Punched in the following:

python3
>>> import pygame

Macs come pre-installed with an older version of python (2.4, I think it might be). Most things that use the newer version of python have a "3" at the end. So to install pygame for python3, you'd use pip3 install pygame.

This may seem excessive, but it is worth it to use python3 over python2.

The docs for pygame itself are fairly easy to follow, and are definitely up to date:
https://www.pygame.org/wiki/GettingStarted
https://www.pygame.org/docs/
Thanks all!
PYGAME now works for python3
Thanks

Ha, shouldn't have song before...

When I threw in the following...

import sys
import pygame
def run_game():
    # Initialize game and create a screen object.
    pygame.init()
    screen = pygame.display.set_mode((1200, 800))
    pygame.display.set_caption("Alien Invasion")
    # Start the main loop for the game.
    while True:
        # Watch for keyboard and mouse events.
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
        # Make the most recently drawn screen visible.
        pygame.display.flip()
run_game()
I get this attributeError:

Error:
Traceback (most recent call last): File "/Users/Dobrasz/Documents/Programming/Python 3/pygame.py", line 2, in <module> import pygame File "/Users/Dobrasz/Documents/Programming/Python 3/pygame.py", line 16, in <module> run_game() File "/Users/Dobrasz/Documents/Programming/Python 3/pygame.py", line 5, in run_game pygame.init() AttributeError: module 'pygame' has no attribute 'init' [Finished in 0.0s with exit code 1] [cmd: ['/usr/local/bin/python3', '-u', '/Users/Dobrasz/Documents/Programming/Python 3/pygame.py']] [dir: /Users/Dobrasz/Documents/Programming/Python 3] [path: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin]
This pygame is not going away is it :-)
(Apr-25-2018, 11:22 AM)Dobrasz Wrote: [ -> ]AttributeError: module 'pygame' has no attribute 'init'
[Finished in 0.0s with exit code 1]
[cmd: ['/usr/local/bin/python3', '-u', '/Users/Dobrasz/Documents/Programming/Python 3/pygame.py']]

You named your file pygame.py. So when you import pygame, you don't ever actually import pygame, as it's just importing whatever file you made yourself. Rename your file (not pygame), and try again :p
If only it as simple...

I changed the file name however the same error appears... 'pygame' has no attribute 'init'.

Please note, I am using Sublime Text to run the program. Not sure if that makes any difference.

I also ran the code in Terminal and I get a syntaxError.

As always thanks for your support.
Pages: 1 2