2

I am teaching myself python, going through some lessons and reading Al Sweigart's book on programming small video games using Python. I am trying to get Pygame working on my laptop. I have tried time and time again to properly install all neccesary tools to run pygame but for some reason I am constantly unsuccessful.

I first tried to install pygame for python 3.6 and after many different attempts I decided to give my computer a factory reset so I could start clean. I understand I could've deleted all residual files using the terminal but being that I'm an amateur I felt more at ease just giving my mac a wipe. Through my research I found that Pygame works best with python v 2.7. I am running Mac OS 10.13(High Sierra).

The first thing I did upon a fresh wipe was open the terminal and process all commands to download things like python2.7, homebrew, pip, pygame. I then tried to import the pygame module but still no prevail. So I decided to go right to the pygame website and download the, pygame-1.9.2pre-py2.7-macosx10.7, file. I see the pygame folder and all of its contents but everytime I try to import the module I receive this import error:

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so: no matching architecture in universal wrapper

I have read that pygame only works with 32 bit version of python but whenever I attempt to download the sole i386/PPC 32 bit version from the website I cant even get IDLE to open at all.

I apologize in advance if my explanation seems a bit choppy. I'm still learning.

MackM
  • 2,906
  • 5
  • 31
  • 45
  • 2
    Hello Michael, and welcome to the site. We like to keep questions very to-the-point here so I went ahead and edited your question, feel free to edit it again if you aren't happy with my changes. And I'm glad you're enjoying Python :) – MackM May 17 '18 at 15:37
  • Welcome to StackOverflow. I would suggest taking the tour: https://stackoverflow.com/tour and reading this: https://stackoverflow.com/help/how-to-ask If edit your question down to the last part it will be more likely that you will get help. Otherwise it's a wall of text and people will just pass it on by. :) – sniperd May 17 '18 at 15:37
  • Does the file in the error message ('Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so') exist? Are you able to see it in your file explorer? – MackM May 17 '18 at 15:38
  • Hey there Mack! Thanks for the edit! I had a feeling my explanation might've been a little much :/. So I actually am able to see it in my finder. I can confirm that ('Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so') does exist. – Michael Carlos May 17 '18 at 15:59
  • This is looking like a 32 vs 64 bit issue, does the answer to this question help you? https://stackoverflow.com/questions/8275808/installing-pygame-for-mac-os-x-10-6-8 – MackM May 17 '18 at 16:14
  • That's what I began to realize. The only problem is that whenever I attempt to download a version of Python that is solely 32 bit I can't even manage to open the IDLE editor. – Michael Carlos May 17 '18 at 16:21
  • I just tried and it appears pygame loaded. But when I try to run a short test file, the line 'import pygame' generates the following error: No module named pygame. i'm very confused... – Natsfan May 17 '18 at 18:10
  • @MichaelCarlos Sorry I can't be more help, but it looks like you've narrowed down your issue a bit. Good luck and welcome to programming! – MackM May 17 '18 at 19:14

3 Answers3

2

Please forget about 32 Bit. Apple is in the process of phasing out support for 32 bit at all, so trying to get something to work there is a short term solution at best.

Also try to not use the shipped Python from Apple. They use it themselves, it's modified slightly from the vanilla one, and fiddling with it might break things.

Your original idea to use python3.6 is the best one. Download and install it, and use the file

https://files.pythonhosted.org/packages/48/d6/230b0d2367824cd51bc9c4baba7e42933c03e34b1ea7ba3812ad5faa4599/pygame-1.9.3-cp36-cp36m-macosx_10_9_intel.whl

to install it using pip.

python3.6 -mpip install pygame

should be enough, the above file is just for reference - it should be picked up by pip.

deets
  • 6,285
  • 29
  • 28
0

You should use pip install pygame to install pygame. Then try to run your code by going to proper directory and running python from command line. I tried running my sample pygame code in my IDE VISUAL STUDIO CODE. I kept getting error messages. When I ran same code from command line it worked fine. Also tried from Atom and it worked fine from there too.

Natsfan
  • 4,093
  • 3
  • 22
  • 29
0

No idea why anyone is still messing about with Python 2 that Apple ships. Come on! Python3 has been out for 10 years.

No idea why anyone is installing MS Office or MS Visual Studio on a Mac. Come on! Surely Mac users buy Macs because they want a proper computer.

Just install homebrew, then install Python 3, then install pygame.

Goto homebrew and install it

Then

brew install python
pip install pygame
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432