Mac OS下pygame安装问题

29 投票
5 回答
13526 浏览
提问于 2025-04-18 02:06

我在安装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)

有什么建议吗?非常感谢!

5 个回答

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

0

我成功在Mac OSX 10.14.4上安装了pygame,使用了以下命令:

brew install sdl sdl_image sdl_mixer sdl_ttf portmidi
sudo -H pip3.8 install pygame

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;

我尝试安装kivy,它是基于pygame的,我试了很多次,但只成功安装过一次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

我也遇到了同样的问题。我尝试了这个问题的所有答案,包括不同版本的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里还是能成功使用它。

41

在这里(OSX Mavericks),我能通过这种方式安装:

brew install sdl sdl_image sdl_mixer sdl_ttf portmidi
pip install https://bitbucket.org/pygame/pygame/get/default.tar.gz

(“默认”分支现在的提交是e3ae850

来源:https://bitbucket.org/pygame/pygame/issue/139/sdlh-not-found-even-thought-it-exists#comment-3822470

你也可以看看这个其他的StackOverflow问题:在OS X上用brew在虚拟环境中使用PyGame?

撰写回答