Pymunk绘图工具不起作用

时间:2017-07-15 16:31:11

标签: python-3.x pyglet pymunk

我正在努力在我的Ubuntu 16.04上设置pymunk。我正在使用virtualenv,我安装了Python 3.5.2,pymunk 5.3.0和cffi 1.11.0。

我先尝试了一个非常简单的代码;基本上,我创建了一个空Space并在其上调用step,一切顺利。但是,当我尝试将其可视化并创建DrawOptions实例时,我会遇到奇怪的错误,我无法解读。此外,我尝试了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编译有问题?

1 个答案:

答案 0 :(得分:3)

发生此错误是因为发布了新版本的pycparser(由cffi使用),该版本破坏了pymunk 5.3.0及更早版本。昨天我发布了一个新版本的Pymunk,5.3.1,解决了这个问题。如果您尝试将Pymunk版本更新为5.3.1,它应该可以正常工作。