使用python 3

时间:2016-01-26 16:49:14

标签: python kivy python-3.4 chipmunk

我试图在我的kivy游戏中添加一些物理,但很难获得" Kivent"和花栗鼠一起跑。 我认为一切都已正确构建,但示例仅以python 2开头,而不是以python3开头。

我收到以下错误消息:

mic@lin:~/python/kivy-kivent-12766f1/examples/4_adding_physics_objects> python3 main.py
[INFO   ] [Logger      ] Record log in /home/mic/.kiv/logs/kivy_16-01-26_48.txt
[INFO   ] [Kivy        ] v1.9.1
[INFO   ] [Python      ] v3.4.1 (default, May 23 2014, 17:48:28) [GCC]
[INFO   ] [Factory     ] 179 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_gif, img_pygame (img_pil, img_ffpyplayer ignored)
[INFO   ] [Window      ] Provider: pygame(['window_egl_rpi'] ignored)
[INFO   ] [GL          ] OpenGL version <b'3.0 Mesa 10.3.7'>
[INFO   ] [GL          ] OpenGL vendor <b'Intel Open Source Technology Center'>
[INFO   ] [GL          ] OpenGL renderer <b'Mesa DRI Intel(R) Haswell Mobile '>
[INFO   ] [GL          ] OpenGL parsed version: 3, 0
[INFO   ] [GL          ] Shading version <b'1.30'>
[INFO   ] [GL          ] Texture max size <8192>
[INFO   ] [GL          ] Texture max units <32>
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [OSC         ] using <multiprocessing> for socket
 Traceback (most recent call last):
   File "main.py", line 8, in <module>
     import kivent_cymunk
   File "/home/mic/python/kivy-kivent-12766f1/examples/4_adding_physics_objects/kivent_cymunk/__init__.py", line 1, in <module>
     from . import physics
 ImportError: dynamic module does not define init function (PyInit_physics)

我整天都搜索过,但没有找到任何答案。 Kivent核心单独工作所以它必须是cymunk或kivent_cymunk的问题。我有一些问题要使用python3来构建这些模块,所以如果您有一个很好的建议来安装这些构建,那么也欢迎。

使用python3设置kivent_cymunk的错误是:

building 'kivent_cymunk.physics' extension
gcc -pthread -Wno-unused-result -Werror=declaration-after-statement -DNDEBUG -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -DOPENSSL_LOAD_CONF -fPIC -I/usr/include/python3.4m -c kivent_cymunk/physics.c -o build/temp.linux-x86_64-3.4/kivent_cymunk/physics.o -std=c99 -ffast-math
In file included from kivent_cymunk/chipmunk/chipmunk.h:116:0,
                 from kivent_cymunk/physics.c:253:
    kivent_cymunk/chipmunk/constraints/cpConstraint.h: In function ‘cpConstraintActivateBodies’:
    kivent_cymunk/chipmunk/constraints/cpConstraint.h:94:2: error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]
  cpBody *b = constraint->b; if(b) cpBodyActivate(b);
  ^
cc1: some warnings being treated as errors
error: command 'gcc' failed with exit status 1

我的系统是:OpenSuse 13.2。

我希望我能够解释这个问题,任何人都可以提供帮助。

提前致谢!

1 个答案:

答案 0 :(得分:2)

因此,经过多个小时的编译和复制,我终于找到了答案。

我发现,花栗鼠没有正确编译,这简直太容易了。问题是,python3的编译器设置了

-Werror=declaration-after-statement

使用python 2时没有设置。要使用python 3正确编译cymunk和kivent_cymunk,我必须添加

-Wno-error=declaration-after-statement

到&#34; extra_compile_args&#34;在setup.py中。之后一切都很顺利(除了很多警告)。

有谁知道为什么这些声明会那么糟糕?或者为什么gcc编译器对python 2和3有不同的参数?

我希望通过这个答案为我节省很多工作。

最佳, 中号