Pygame 找不到包含文件“sdl.h”

Bug*_*boy 5 python pygame sdl

我正在尝试在 Windows 上构建一个使用 Pygame 的下载的 Python 应用程序。我已经安装了Python 2.5和Pygame 1.7.1。我是 Python 新手,但我只是尝试在 Windows 控制台命令行上输入顶级 .py 文件的名称。(我使用的是 Win XP Pro。)

这是我收到的消息。

C:\Python25\include\pygame\pygame.h(68) : 致命错误 C1083: 无法打开包含文件: 'SDL.h': 没有这样的文件或目录

我认为 Pygame 是构建在 SDL 之上的,不需要单独安装 SDL。尽管如此,我安装了 SDL 1.2.13 并将 SDL include 文件夹添加到我的 %INCLUDE% 环境变量中。还是没有运气。

我注意到C:\Python25\Lib\site-packages\pygame包含几个 SDL*.DLL 文件,但 python 树中的任何位置都没有 sdl.h 头文件。当然,我可以将 sdl 头文件复制到C:\Python25\include\pygame文件夹中,但这是一个令人厌恶的想法。

有人知道设置的正确方法吗?

编辑: 该应用程序是“企鹅机器”pygame 应用程序

nos*_*klo 5

我尝试编译并在我的 Linux 机器上遇到相同的错误:

\n\n
$ python setup.py build\nDBG> include = ['/usr/include', '/usr/include/python2.6', '/usr/include/SDL']\nrunning build\nrunning build_ext\nbuilding 'surfutils' extension\ncreating build\ncreating build/temp.linux-i686-2.6\ncreating build/temp.linux-i686-2.6/src\ngcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include -I/usr/include/python2.6 -I/usr/include/SDL -I/usr/include/python2.6 -c src/surfutils.c -o build/temp.linux-i686-2.6/src/surfutils.o\nIn file included from src/surfutils.c:1:\n/usr/include/python2.6/pygame/pygame.h:68:17: error: SDL.h: Arquivo ou diret\xc3\xb3rio inexistente\nIn file included from src/surfutils.c:1:\n/usr/include/python2.6/pygame/pygame.h:312: error: expected specifier-qualifier-list before \xe2\x80\x98SDL_VideoInfo\xe2\x80\x99\n/usr/include/python2.6/pygame/pygame.h:350: error: expected specifier-qualifier-list before \xe2\x80\x98SDL_Surface\xe2\x80\x99\nsrc/surfutils.c:5: error: expected \xe2\x80\x98)\xe2\x80\x99 before \xe2\x80\x98*\xe2\x80\x99 token\nsrc/surfutils.c: In function \xe2\x80\x98PyCollisionPoint\xe2\x80\x99:\nsrc/surfutils.c:74: error: \xe2\x80\x98SDL_Surface\xe2\x80\x99 undeclared (first use in this function)\nsrc/surfutils.c:74: error: (Each undeclared identifier is reported only once\nsrc/surfutils.c:74: error: for each function it appears in.)\nsrc/surfutils.c:74: error: \xe2\x80\x98surf1\xe2\x80\x99 undeclared (first use in this function)\nsrc/surfutils.c:74: error: \xe2\x80\x98surf2\xe2\x80\x99 undeclared (first use in this function)\nsrc/surfutils.c:74: warning: left-hand operand of comma expression has no effect\nsrc/surfutils.c:92: error: \xe2\x80\x98PySurfaceObject\xe2\x80\x99 has no member named \xe2\x80\x98surf\xe2\x80\x99\nsrc/surfutils.c:97: error: \xe2\x80\x98SDL_SRCALPHA\xe2\x80\x99 undeclared (first use in this function)\nsrc/surfutils.c:111: error: \xe2\x80\x98PySurfaceObject\xe2\x80\x99 has no member named \xe2\x80\x98surf\xe2\x80\x99\nsrc/surfutils.c:161: warning: implicit declaration of function \xe2\x80\x98collisionPoint\xe2\x80\x99\nerror: command 'gcc' failed with exit status 1\n
Run Code Online (Sandbox Code Playgroud)\n\n

似乎它试图编译一个名为 的扩展,surfutils该扩展需要 SDL 开发标头。

\n\n

所以我libsdl1.2-dev使用我的分发包管理器安装了该包,并且它工作得很好。您必须安装 SDL 开发标头才能为您的系统构建它。

\n\n

所以你的问题实际上是:如何在 Windows 上安装 SDL 开发标头,以及如何让程序使用它们?

\n\n

嗯,我可以回答第二个问题。您必须编辑 setup.py:

\n\n
#!/usr/bin/env python2.3\n\nfrom distutils.core       import setup, Extension\nfrom distutils.sysconfig  import get_config_vars\n\nincludes = []\nincludes.extend(get_config_vars('INCLUDEDIR'))\nincludes.extend(get_config_vars('INCLUDEPY'))\nincludes.append('/usr/include/SDL')\n\nprint 'DBG> include =', includes\n\nsetup(name='surfutils',\n      version='1.0',\n      ext_modules=[Extension(\n                    'surfutils', \n                    ['src/surfutils.c'], \n                    include_dirs=includes,\n                  )],\n     )\n
Run Code Online (Sandbox Code Playgroud)\n\n

更改第 9 行。它说:

\n\n
includes.append('/usr/include/SDL')\n
Run Code Online (Sandbox Code Playgroud)\n\n

将此路径更改为 SDL 标头所在的位置,即:

\n\n
includes.append(r'C:\\mydevelopmentheaders\\SDL')\n
Run Code Online (Sandbox Code Playgroud)\n\n

给游戏开发者留言,说明您遇到了此问题。它可以提供一种在您的平台上查找 SDL 标头的更好方法。

\n