简体   繁体   中英

Pygame on Mac - How do I install?

Doing this on a mac. I've installed the package from the website but when I run a script with import pygame it says it doesn't exist. Looked online and it says I need to run the configure.py file but I can't seem to locate that file. Any tips?

Here is my code so far:

import pygame  
screen = pygame.display.set_mode((640, 480)) 
running = 1  
while running:
     event = pygame.event.poll()
     if event.type == pygame.QUIT:
         running = 0
     screen.fill((0, 0, 0))
     pygame.draw.line(screen, (0, 0, 255), (0, 0), (639, 479))
     pygame.draw.aaline(screen, (0, 0, 255), (639, 0), (0, 479))
     pygame.display.flip()

The script is probably using a version of python that you did not install pygame into.

I believe the pygame binary installer (which is what I assume you meant by "package from the website") installs into system python. Check which version you are using by default. This is what it should look like when you run "which python" from Terminal.app:

$ which python
/usr/bin/python

This happens all the time if you use MacPorts, Fink, or a Python.org binary installer to install python. If you are using MacPorts or Fink, python may have even been installed without your knowledge as a dependency to something else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM