在Mac OS上安装Pygame出现问题

29

我安装pygame包时遇到了以下问题。

In file included from src/_numericsurfarray.c:23:
src/pygame.h:106:10: fatal error: 'SDL.h' file not found
#include <SDL.h>
         ^
1 error generated.
error: Setup script exited with error: command 'gcc' failed with exit status 1

系统信息

  • Mac OS-10.9.2
  • Python版本- Python 2.7.5 :: Anaconda 1.6.1 (x86_64)

您有任何建议将不胜感激。谢谢。


1
这可能会有所帮助..https://groups.google.com/forum/#!topic/pygame-mirror-on-google-groups/FLNCI3-cOFQ - Arvind
2
按照建议运行brew命令后出现以下错误: src/pygame.h:106:10: 致命错误:'SDL.h' 文件未找到 #include <SDL.h> ^ 1 error generated. 错误:设置脚本退出时出错:命令“gcc”失败,退出状态为1 - J4cK
5个回答

41

9
只需要执行 brew install sdl 就足够了,但我猜有些部分可能不能正常工作。 - Andrei

2

我曾经遇到同样的问题。我尝试了所有与此问题相关的答案版本,包括pip和pip3的变化。最终,对我有效的是:

sudo easy_install pygame

请注意,然而:(1) https://setuptools.readthedocs.io/en/latest/easy_install.html 表示easy_install已被弃用,并建议使用pip。(2) pygame安装在旧的标准python 2.7文件夹中,而不是我刚刚安装的python 3.8.3 -- 尽管我能够在VSCode中成功使用它。


1
我的系统也是OSX10.9.2,我也遇到了你的问题,我还在尝试一些方法;也许这会对你有所帮助:
以下是步骤:
1.Install [Quartz](https://xquartz.macosforge.org/landing/);
2.Install Xcode-Command-Line,
  but you may cant install it by `xcode-select --install`,
  so you can down from 
  https://developer.apple.com/downloads/index.action ;
  I suggest you setup xcode,and this really solute my some problem;
3.`brew tap homebrew/headonly`
  `brew install smpeg --HEAD`
  `brew install sdl sdl_image sdl_mixer sdl_ttf portmidi`

4. `sudo pip install hg+http://bitbucket.org/pygame/pygame`;
   if you clone this repo and try `python setup.py install`,you may meet some weird problem;

我尝试安装基于pygame的kivy,多次尝试但只成功安装了一次pygame。然后我卸载了它,再次安装就失败了 ;( 一些参考:

http://jamesfriend.com.au/installing-pygame-python-mac-os-108-mountain-lion http://juliaelman.com/blog/2013/04/02/installing-pygame-on-osx-mountain-lion/

=======更新

现在我已成功安装了Pygame,请记得安装Xcode,而不仅仅是Xcode命令行工具!


2
请勿仅发布答案链接-如果该博客失效,您的答案将不再有用。在您的答案中提供相关步骤,并使用博客作为支持。 - thegrinner
抱歉,这是我的第一个答案,我现在会更改它! - gkiwi

0
我成功地在Mac OSX 10.14.4上安装了pygame,使用以下方法:
brew install sdl sdl_image sdl_mixer sdl_ttf portmidi sudo -H pip3.8 install pygame

0

这对我有用:

如果您没有通过homebrew安装Python/pip(而是使用系统安装的Python),则可能需要运行sudo pip3 install pygame。

在运行pip3 install pygame之前,我还安装了XCode的命令行工具以及XQuartz和以下homebrew软件包:brew install sdl sdl_image sdl_mixer sdl_ttf smpeg portmidi。

如果homebrew无法安装smpeg,则可能需要执行以下操作:

brew tap homebrew/headonly brew install --HEAD smpeg

来源:http://jamesfriend.com.au/installing-pygame-python-mac-os-108-mountain-lion


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接