4

I'm trying to install pygame.

My envrionment is

macOS 10.14.6 Mohave

Python 3.7.4 (downloaded from python.org)

I'm following the instructions on the Pygame site, namely using

pip install pygame

However this is failing with a fatal error, which can be summarised as fatal error:SDL.h filenot found The full install output is shown below.

Running setup.py install for pygame ... error
ERROR: Command errored out with exit status 1:
 command: /Library/Frameworks/Python.framework/Versions/3.8/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/tmp/pip-install-mtm_fm2t/pygame/setup.py'"'"'; __file__='"'"'/private/tmp/pip-install-mtm_fm2t/pygame/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/tmp/pip-record-vrvsxslr/install-record.txt --single-version-externally-managed --compile
     cwd: /private/tmp/pip-install-mtm_fm2t/pygame/
Complete output (219 lines):
running install
running build
running build_py
creating build
creating build/lib.macosx-10.9-x86_64-3.8
creating build/lib.macosx-10.9-x86_64-3.8/pygame
copying src_py/surfarray.py -> build/lib.macosx-10.9-x86_64-3.8/pygame
copying src_py/sysfont.py -> build/lib.macosx-10.9-x86_64-3.8/pygame
copying src_py/_camera_vidcapture.py -> build/lib.macosx-10.9-x86_64-3.8/pygame

...whole bunch of copying removed for brevity...

copying examples/pixelarray.py -> build/lib.macosx-10.9-x86_64-3.8/pygame/examples
copying examples/dropevent.py -> build/lib.macosx-10.9-x86_64-3.8/pygame/examples
running build_ext
building 'pygame.gfxdraw' extension
creating build/temp.macosx-10.9-x86_64-3.8
creating build/temp.macosx-10.9-x86_64-3.8/src_c
creating build/temp.macosx-10.9-x86_64-3.8/src_c/SDL_gfx
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DENABLE_NEWBUF=1 -I/NEED_INC_PATH_FIX -I/Library/Frameworks/Python.framework/Versions/3.8/include/python3.8 -c src_c/gfxdraw.c -o build/temp.macosx-10.9-x86_64-3.8/src_c/gfxdraw.o
In file included from src_c/gfxdraw.c:33:
In file included from src_c/pygame.h:32:
src_c/_pygame.h:216:10: fatal error: 'SDL.h' file not found
#include <SDL.h>
         ^~~~~~~
1 error generated.
---
For help with compilation see:
    https://www.pygame.org/wiki/MacCompile
To contribute to pygame development see:
    https://www.pygame.org/contribute.html
---
error: command 'gcc' failed with exit status 1
ERROR: Command errored out with exit status 1: 
   /Library/Frameworks/Python.framework/Versions/3.8/bin/python3 -u -c 'import sys, 
   setuptools, tokenize; sys.argv[0] = '"'"'/private/tmp/pip-install- 
   mtm_fm2t/pygame/setup.py'"'"'; __file__='"'"'/private/tmp/pip-install- 
  mtm_fm2t/pygame/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/tmp/pip-record-vrvsxslr/install-record.txt --single-version-externally-managed --compile Check the logs for full command output.

The file SDL.h does exist when I search in finder, so i don't know why this install is failing.

I've tried the following to solve this but with no success.

  1. installing with pip3 install pygame
  2. installing with pip3 install pygame--2.0.0_dev4 option
  3. And i've even tried downloading the SDL2 source and compiling.

They all fail (the SDL make fails chronically with errors around lzma.h

Has anyone got pygame running on macOS and Python 3.7.4 and can provide a list of detailed instructions and pre-requisites.

AndyS1202
  • 41
  • 3
  • Using Anaconda? – norok2 Dec 14 '19 at 10:22
  • always put full error message (starting at word "Traceback") in question (not comment) as text (not screenshot). There are other useful information. – furas Dec 14 '19 at 10:30
  • if you get error when you install `PyGame 1.9.x` then you would have to use `SDL 1.2`, not `SDL2` – furas Dec 14 '19 at 10:32
  • No anaconda.... just a raw install with pip. How do i install SDL1.2? - pip install pygame--1.2 – AndyS1202 Dec 16 '19 at 00:45
  • Does this answer your question? [pygame installation issue in mac os](https://stackoverflow.com/questions/22974339/pygame-installation-issue-in-mac-os) – AMC Feb 08 '20 at 03:01

3 Answers3

4

I just struggled with this same issue and was finally able to install pygame on a Mac with Mojave by using this command line:

pip3 install pygame --only-binary :all:

This will install a precompiled version of pygame and thus avoids the issue with missing header files (like SDL.h in your error message) which is occurring because pip is trying to compile pygame from source code that looks for these headers in /usr/include. With the latest updates to Mojave and Catalina, Apple no longer has a /usr/include directory. I did check the version of pygame installed with the --only-binary option and see it is a 2.0.0 dev version but so far it seems to work.

MrBean Bremen
  • 14,916
  • 3
  • 26
  • 46
Dottie11
  • 41
  • 4
  • Hey Dottie, Thanks for this. I did run this, but as the 'easy_install' method worked I got the 'requirement already satisfied' notification. As an aside, the option the --only-binary if anyone else is trying this approach. – AndyS1202 Jan 22 '20 at 01:14
1

I was able to solve this issue by using easy_install pygame instead of pip. I suspect that it has something to do with python 3.8.

enbell
  • 11
  • 3
  • This seems to have installed ok. It has put pygame 2.0.0.dev6 in, so I'm guessing a development release, not the latest stable release. Buy hey, I'm only messing around teaching myself so not too hung up on versions for now. Thanks for the info! – AndyS1202 Jan 22 '20 at 01:09
1

I struggled a lot in installing pygame on macOS Catalina. I tried creating the virtual env as well as many other options but Nothing worked for me. The default python is located in /usr/bin/python while the python3 that I installed is located in /Library/Frameworks/Python.framework/Versions/3.8/bin/python3 so instead of using pip install pygame i triedeasy_install-3.8 pygame and it worked for me and when I opened the bin folder in /Library/Frameworks/Python.framework/Versions/3.8 location it has an easy_install-3.8 file. I do not know much about it but I think it has something to do with the python3.8

elprup
  • 1,960
  • 2
  • 18
  • 32