2017-07-15 105 views
1

我很努力在我的Ubuntu 16.04上設置pymunk。我使用的是virtualenv,我安裝了Python 3.5.2,pymunk 5.3.0和cffi 1.11.0。pymunk drawing utils does not working

我先試了一個非常簡單的代碼;基本上,我創建了一個空的Space,並調用step就可以了,一切都很順利。但是,當我嘗試將其可視化並創建實例時,出現奇怪的錯誤,這是我無法解讀的。另外,我嘗試了matplotlib_utilpygame_util,但都未能創建DrawOptions

這是代碼片段我用:

import pymunk 
    import pyglet 
    import pymunk.pyglet_util 

    s = pymunk.Space() 
    options = pymunk.pyglet_util.DrawOptions() 

    s.debug_draw(options) 

    # s.step(0.02) 

這是輸出我得到:

Loading chipmunk for Linux (64bit) [/home/wm/.virtualenvs/cv/lib/python3.5/site-packages/pymunk/libchipmunk.so] 
    Traceback (most recent call last): 
     File "/home/wm/.virtualenvs/cv/lib/python3.5/site-packages/cffi-1.11.0-py3.5-linux-x86_64.egg/cffi/api.py", line 167, in _typeof 
     result = self._parsed_types[cdecl] 
    KeyError: 'typedef void (*cpSpaceDebugDrawCircleImpl)(cpVect pos, cpFloat angle, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor, cpDataPointer data)' 

    During handling of the above exception, another exception occurred: 

    Traceback (most recent call last): 
     File "/home/wm/.virtualenvs/cv/lib/python3.5/site-packages/cffi-1.11.0-py3.5-linux-x86_64.egg/cffi/cparser.py", line 276, in _parse 
     ast = _get_parser().parse(fullcsource) 
     File "/home/wm/.virtualenvs/cv/lib/python3.5/site-packages/pycparser/c_parser.py", line 152, in parse 
     debug=debuglevel) 
     File "/home/wm/.virtualenvs/cv/lib/python3.5/site-packages/pycparser/ply/yacc.py", line 331, in parse 
     return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc) 
     File "/home/wm/.virtualenvs/cv/lib/python3.5/site-packages/pycparser/ply/yacc.py", line 1199, in parseopt_notrack 
     tok = call_errorfunc(self.errorfunc, errtoken, self) 
     File "/home/wm/.virtualenvs/cv/lib/python3.5/site-packages/pycparser/ply/yacc.py", line 193, in call_errorfunc 
     r = errorfunc(token) 
     File "/home/wm/.virtualenvs/cv/lib/python3.5/site-packages/pycparser/c_parser.py", line 1761, in p_error 
     column=self.clex.find_tok_column(p))) 
     File "/home/wm/.virtualenvs/cv/lib/python3.5/site-packages/pycparser/plyparser.py", line 66, in _parse_error 
     raise ParseError("%s: %s" % (coord, msg)) 
    pycparser.plyparser.ParseError: <cdef source string>:2:16: before: cpSpaceDebugDrawCircleImpl 

    During handling of the above exception, another exception occurred: 

    Traceback (most recent call last): 
     File "pmtest2.py", line 5, in <module> 
     options = pymunk.pyglet_util.DrawOptions() 
     File "/home/wm/.virtualenvs/cv/lib/python3.5/site-packages/pymunk/pyglet_util.py", line 89, in __init__ 
     super(DrawOptions, self).__init__() 
     File "/home/wm/.virtualenvs/cv/lib/python3.5/site-packages/pymunk/space_debug_draw_options.py", line 51, in __init__ 
     @ffi.callback("typedef void (*cpSpaceDebugDrawCircleImpl)" 
     File "/home/wm/.virtualenvs/cv/lib/python3.5/site-packages/cffi-1.11.0-py3.5-linux-x86_64.egg/cffi/api.py", line 375, in callback 
     cdecl = self._typeof(cdecl, consider_function_as_funcptr=True) 
     File "/home/wm/.virtualenvs/cv/lib/python3.5/site-packages/cffi-1.11.0-py3.5-linux-x86_64.egg/cffi/api.py", line 170, in _typeof 
     result = self._typeof_locked(cdecl) 
     File "/home/wm/.virtualenvs/cv/lib/python3.5/site-packages/cffi-1.11.0-py3.5-linux-x86_64.egg/cffi/api.py", line 155, in _typeof_locked 
     type = self._parser.parse_type(cdecl) 
     File "/home/wm/.virtualenvs/cv/lib/python3.5/site-packages/cffi-1.11.0-py3.5-linux-x86_64.egg/cffi/cparser.py", line 476, in parse_type 
     return self.parse_type_and_quals(cdecl)[0] 
     File "/home/wm/.virtualenvs/cv/lib/python3.5/site-packages/cffi-1.11.0-py3.5-linux-x86_64.egg/cffi/cparser.py", line 479, in parse_type_and_quals 
     ast, macros = self._parse('void __dummy(\n%s\n);' % cdecl)[:2] 
     File "/home/wm/.virtualenvs/cv/lib/python3.5/site-packages/cffi-1.11.0-py3.5-linux-x86_64.egg/cffi/cparser.py", line 278, in _parse 
     self.convert_pycparser_error(e, csource) 
     File "/home/wm/.virtualenvs/cv/lib/python3.5/site-packages/cffi-1.11.0-py3.5-linux-x86_64.egg/cffi/cparser.py", line 307, in convert_pycparser_error 
     raise CDefError(msg) 
    cffi.error.CDefError: cannot parse "typedef void (*cpSpaceDebugDrawCircleImpl)(cpVect pos, cpFloat angle, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor, cpDataPointer data)" 
    <cdef source string>:2:16: before: cpSpaceDebugDrawCircleImpl 

你認爲是什麼原因造成的?那是我使用的python版本,還是cffi編譯錯誤?

回答

3

發生此錯誤是因爲發佈了pycparser(由cffi使用)的新版本,並且該版本打破了pymunk 5.3.0及更早版本。昨天我發佈了一個新版本的Pymunk 5.3.1,並解決了這個問題。如果你嘗試更新你的Pymunk版本到5.3.1,它應該可以工作。