![](/img/trans.png)
[英]How to use factorplot to annotate bars with categorical values or to plot 4 variables?
[英]How to use annotate=True on Cythonize()
我是 Cython 的新手,但是按照官方文档中的这个基本指南让它工作了:
它只是说:“Cython 有一种方法可以将与 Python 对象和 Python 的 C-API 交互发生的位置可视化。为此,将 annotate=True 参数传递给 cythonize()。它会生成一个 HTML 文件。”
我很惊讶我不能只用谷歌搜索这个,或者 stackoverflow 上没有人问过这个问题。 但我不知道如何让它工作。 它没有具体显示它想要什么。 所以我尝试了最明显的语法(在 Setup.py 中):
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize("gpcython.pyx", annotate=True)
)
虽然这不会引发错误,但我也没有看到生成任何 HTML。
我在 Windows 上使用最新版本的 Python 3.7 和 Cython 0.29.12。
https://cython.readthedocs.io/en/latest/src/tutorial/cython_tutorial.html
这是我最终使用的现在似乎有效的方法:
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)
)
您可以尝试删除生成的 c 或 cpp 文件。 如果 pyx 没有变化,cython 不会尝试重复构建。 我不知道 cython 如何跟踪构建依赖项。 我想这类似于make
工作方式。
也许晚了,但我解决了这个问题,如下所示:
更改.pyx
源文件或删除.c
文件并再次运行setup.py
以强制cython
再次重建它。
--force
参数可能不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.