[英]How to use annotate=True on Cythonize()
I'm new to Cython, but got it working by following this basic guide from the official docs :我是 Cython 的新手,但是按照官方文档中的这个基本指南让它工作了:
All it says is: "Cython has a way to visualise where interaction with Python objects and Python's C-API is taking place. For this, pass the annotate=True parameter to cythonize(). It produces a HTML file."它只是说:“Cython 有一种方法可以将与 Python 对象和 Python 的 C-API 交互发生的位置可视化。为此,将 annotate=True 参数传递给 cythonize()。它会生成一个 HTML 文件。”
I'm very surprised that I couldn't just Google this one or that no one on stackoverflow has asked this.我很惊讶我不能只用谷歌搜索这个,或者 stackoverflow 上没有人问过这个问题。 But I can't figure out how to get it to work.但我不知道如何让它工作。 It doesn't show specifically what it wants.它没有具体显示它想要什么。 So I tried the most obvious syntax (in Setup.py):所以我尝试了最明显的语法(在 Setup.py 中):
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize("gpcython.pyx", annotate=True)
)
While this does not throw an error, I do not see any HTML being generated either.虽然这不会引发错误,但我也没有看到生成任何 HTML。
I am on windows using the latest version of Python 3.7 with Cython 0.29.12.我在 Windows 上使用最新版本的 Python 3.7 和 Cython 0.29.12。
https://cython.readthedocs.io/en/latest/src/tutorial/cython_tutorial.html https://cython.readthedocs.io/en/latest/src/tutorial/cython_tutorial.html
Here is what I finally used that now seems to work:这是我最终使用的现在似乎有效的方法:
from distutils.core import setup
from Cython.Build import cythonize
import Cython.Compiler.Options
Cython.Compiler.Options.annotate = True
setup(
ext_modules = cythonize("gpcython.pyx", annotate=True)
)
You can try to remove the generated c or cpp file.您可以尝试删除生成的 c 或 cpp 文件。 If there's no change in pyx, cython won't try to repeat the build.如果 pyx 没有变化,cython 不会尝试重复构建。 I don't know how cython tracks the build dependencies.我不知道 cython 如何跟踪构建依赖项。 I guess it's similar to how make
works.我想这类似于make
工作方式。
Maybe late but I solved this problem like below:也许晚了,但我解决了这个问题,如下所示:
Change .pyx
source file or remove .c
file and run setup.py
again to force cython
to rebuild it again.更改.pyx
源文件或删除.c
文件并再次运行setup.py
以强制cython
再次重建它。
--force
argument may not work. --force
参数可能不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.