سؤال

أحاول إنشاء تطبيق Python تم تنزيله على Windows يستخدم Pygame. لقد قمت بتثبيت Python 2.5 و Pygame 1.7.1. أنا جديد على Python ، لكنني حاولت فقط كتابة اسم ملف .py الأعلى على سطر الأوامر Windows Console. (أنا أستخدم Win XP Pro.)

هذه هي الرسالة التي أحصل عليها.

C: python25 include pygame pygame.h (68): خطأ فادح C1083: لا يمكن فتح ملف: 'sdl.h': لا يوجد مثل هذا الملف أو الدليل

اعتقدت أن Pygame تم بناؤه على رأس SDL وأن تثبيت SDL منفصل لم يكن ضروريًا. ومع ذلك ، قمت بتثبيت SDL 1.2.13 وأضفت مجلد SDL لتشمل المجلد إلى نسبة ٪ متغير البيئة. لا يزال لا حظ.

لاحظت ذلك C: Python25 lib site-packages pygame يتضمن العديد من ملفات SDL*.DLL ، ولكن لا يوجد ملف رأس SDL.H في أي مكان في شجرة Python. بالطبع ، يمكنني نسخ رؤوس SDL إلى C: Python25 include pygame المجلد ، لكن هذه فكرة بغيضة.

أي شخص يعرف الطريقة الصحيحة لإعداد الأشياء؟

تعديل:التطبيق هو تطبيق "آلة البطريق" Pygame.

هل كانت مفيدة؟

المحلول

حاولت التجميع وحصلت على نفس الأخطاء في صندوق Linux الخاص بي:

$ 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.

لذلك قمت بتثبيت libsdl1.2-dev حزمة باستخدام مدير حزمة التوزيع الخاص بي وعمل بشكل جيد. يجب عليك تثبيت رؤوس تطوير SDL من أجل بنائه لنظامك.

لذا فإن سؤالك حقًا هو: كيف أقوم بتثبيت رؤوس تطوير SDL على Windows ، وكيف أجعل البرنامج يستخدمها؟

حسنًا ، يمكنني الإجابة على السؤال الثاني. يجب عليك تحرير 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. يقول:

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

قم بتغيير هذا المسار إلى أينما كانت رؤوس SDL الخاصة بك ، أي:

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

اترك ملاحظة لمطور اللعبة ليقول إنك تواجه هذه المشكلة. يمكن أن يوفر طريقة أفضل للعثور على رؤوس SDL على منصتك.

نصائح أخرى

عندما تقوم بتجميع شيء ما ، يبحث المترجم عن ملفات الرأس في العديد من الدلائل ، وبعضها متشدد ويبني ، وعادة ما يتم تقديم بعضها كوسيطات للمترجم (على سبيل المثال "GCC -I/usr/local/include ..."). تخمين واحد هو أنك تفتقد هذا. إذا لم تكن تحقق من الأسباب المحتملة الأخرى رسالة الخطأ الخاصة بك.

ستحتاج إلى الحصول على SDL تم تثبيت مكتبات التطوير ، ولكن بما أنك تقول "يمكنني نسخ رؤوس SDL" ، يبدو أن لديك بالفعل. ثم مشكلتك هي فقط للحصول على المترجم للنظر في الدليل الذي يحتوي على تلك الملفات.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top