0

sfml.pxd:

cdef extern from "SFML/Window.hpp" namespace "sf":

    cdef cppclass VideoMode:
        VideoMode(unsigned int, unsigned int) except +

    cdef cppclass Window:
        Window(VideoMode, String) except + 
        void display()

显示.pyx:

cimport sfml

cdef class Window:

    cdef sfml.Window* _this

    def __cinit__(self, unsigned int width, unsigned int height):

        self._this = new sfml.Window(sfml.VideoMode(width, height), "title")

    def __dealloc__(self):

        del self._this

    def display(self):

        self._this.display()

设置.py:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

setup(
    cmdclass = {'build_ext': build_ext},
    ext_modules = [
        Extension("display", ["display.pyx"],
        language='c++',
        libraries=["sfml-system", "sfml-window"])
    ]
)

运行时的错误python setup.py build

running build
running build_ext
cythoning display.pyx to display.cpp
Traceback (most recent call last):
  File "setup.py", line 10, in <module>
    libraries=["sfml-system", "sfml-window"])
  File "/usr/lib/python3.3/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/lib/python3.3/distutils/dist.py", line 917, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python3.3/distutils/dist.py", line 936, in run_command
    cmd_obj.run()
  File "/usr/lib/python3.3/distutils/command/build.py", line 126, in run
    self.run_command(cmd_name)
  File "/usr/lib/python3.3/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/usr/lib/python3.3/distutils/dist.py", line 936, in run_command
    cmd_obj.run()
  File "/usr/lib/python3.3/site-packages/Cython/Distutils/build_ext.py", line 163, in run
    _build_ext.build_ext.run(self)
  File "/usr/lib/python3.3/distutils/command/build_ext.py", line 354, in run
    self.build_extensions()
  File "/usr/lib/python3.3/site-packages/Cython/Distutils/build_ext.py", line 170, in build_extensions
    ext.sources = self.cython_sources(ext.sources, ext)
  File "/usr/lib/python3.3/site-packages/Cython/Distutils/build_ext.py", line 317, in cython_sources
    full_module_name=module_name)
  File "/usr/lib/python3.3/site-packages/Cython/Compiler/Main.py", line 608, in compile
    return compile_single(source, options, full_module_name)
  File "/usr/lib/python3.3/site-packages/Cython/Compiler/Main.py", line 549, in compile_single
    return run_pipeline(source, options, full_module_name)
  File "/usr/lib/python3.3/site-packages/Cython/Compiler/Main.py", line 386, in run_pipeline
    from . import Pipeline
  File "/usr/lib/python3.3/site-packages/Cython/Compiler/Pipeline.py", line 7, in <module>
    from .Visitor import CythonTransform
  File "Visitor.py", line 10, in init Cython.Compiler.Visitor (/build/src/Cython-0.19/Cython/Compiler/Visitor.c:15987)
ImportError: No module named 'ExprNodes'

显然,它找不到名为“ExprNodes”的东西,但我不认为我的 Cython 安装被破坏了,因为我前段时间成功地包装了一个不同的 C++ 库,而且我没有遇到这个问题。

我正在使用 Cython 0.19。

我将不胜感激您可以提供的任何帮助/见解。

谢谢。

4

1 回答 1

1

更仔细地查看回溯,我发现 Cython 在它自己的编译代码中失败了。这可能确实是一个错误,很抱歉第一次错过它。

你能做什么:

  • 创建一个干净的 virtualenv,在那里安装 Cython 并检查它是否有效。(版本 0.19.1 是最新的)。
  • 创建另一个 virtualenv,但这次使用python setup.py install --no-cython-compile.

如果其中任何一个失败,请将您的详细配置(linux 发行版和版本、python 版本、gcc 版本等)发布到 cython-devel 邮件列表。

顺便说一句,你以前成功的项目还能编译吗?

于 2013-05-24T05:11:18.163 回答