Pygame 找不到包含文件“sdl.h"; [英] Pygame cannot find include file "sdl.h"

查看:79
本文介绍了Pygame 找不到包含文件“sdl.h";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to build a downloaded Python app on Windows that uses Pygame. I have installed Python 2.5 and Pygame 1.7.1. I am new to Python, but I just tried typing the name of the top level .py file on a Windows console command line. (I'm using Win XP Pro.)

这是我收到的消息.

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

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

I thought that Pygame was built on top of SDL and that a separate SDL install was not necessary. Nevertheless, I installed SDL 1.2.13 and added the SDL include folder to my %INCLUDE% environment variable. Still no luck.

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

I noticed that C:\Python25\Lib\site-packages\pygame includes several SDL*.DLL files, but there is no sdl.h header file anywhere in the python tree. Of course, I could copy the sdl headers into the C:\Python25\include\pygame folder, but that is a distasteful idea.

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

Anybody know the right way to set things up?

该应用程序是企鹅机器"pygame 应用程序.

推荐答案

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

I tried compiling and got the same errors on my linux box:

$ python setup.py build
DBG> include = ['/usr/include', '/usr/include/python2.6', '/usr/include/SDL']
running build
running build_ext
building 'surfutils' extension
creating build
creating build/temp.linux-i686-2.6
creating build/temp.linux-i686-2.6/src
gcc -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
In file included from src/surfutils.c:1:
/usr/include/python2.6/pygame/pygame.h:68:17: error: SDL.h: Arquivo ou diretório inexistente
In file included from src/surfutils.c:1:
/usr/include/python2.6/pygame/pygame.h:312: error: expected specifier-qualifier-list before ‘SDL_VideoInfo’
/usr/include/python2.6/pygame/pygame.h:350: error: expected specifier-qualifier-list before ‘SDL_Surface’
src/surfutils.c:5: error: expected ‘)’ before ‘*’ token
src/surfutils.c: In function ‘PyCollisionPoint’:
src/surfutils.c:74: error: ‘SDL_Surface’ undeclared (first use in this function)
src/surfutils.c:74: error: (Each undeclared identifier is reported only once
src/surfutils.c:74: error: for each function it appears in.)
src/surfutils.c:74: error: ‘surf1’ undeclared (first use in this function)
src/surfutils.c:74: error: ‘surf2’ undeclared (first use in this function)
src/surfutils.c:74: warning: left-hand operand of comma expression has no effect
src/surfutils.c:92: error: ‘PySurfaceObject’ has no member named ‘surf’
src/surfutils.c:97: error: ‘SDL_SRCALPHA’ undeclared (first use in this function)
src/surfutils.c:111: error: ‘PySurfaceObject’ has no member named ‘surf’
src/surfutils.c:161: warning: implicit declaration of function ‘collisionPoint’
error: command 'gcc' failed with exit status 1

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

Seems like it tries to compile a extension called surfutils which needs SDL development headers.

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

So I installed the libsdl1.2-dev package using my distribution package manager and it worked just fine. You must install SDL development headers in order to build it for your system.

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

So your question really is: How do I install SDL development headers on windows, and how I make the program use them?

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

Well, I can answer the second question. You must edit setup.py:

#!/usr/bin/env python2.3

from distutils.core       import setup, Extension
from distutils.sysconfig  import get_config_vars

includes = []
includes.extend(get_config_vars('INCLUDEDIR'))
includes.extend(get_config_vars('INCLUDEPY'))
includes.append('/usr/include/SDL')

print 'DBG> include =', includes

setup(name='surfutils',
      version='1.0',
      ext_modules=[Extension(
                    'surfutils', 
                    ['src/surfutils.c'], 
                    include_dirs=includes,
                  )],
     )

更改第 9 行.它说:

Change line 9. It says:

includes.append('/usr/include/SDL')

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

Change this path to wherever your SDL headers are, i.e.:

includes.append(r'C:\mydevelopmentheaders\SDL')

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

Leave a note to the game developer to say you're having this trouble. It could provide a better way of finding SDL headers on your platform.

这篇关于Pygame 找不到包含文件“sdl.h";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆