如何在 Cythonize() 上使用 annotate=True
How to use annotate=True on Cythonize()
我是 Cython 的新手,但通过遵循此 basic guide from the official docs:
它只说:
“Cython 有一种方法可以可视化与 Python 对象和 Python 的 C-API 发生交互的位置。为此,将 annotate=True 参数传递给 cythonize()。它生成一个 HTML 文件。"
我很惊讶我不能只 Google 这个问题,或者 Whosebug 上没有人问过这个问题。但我不知道如何让它工作。它没有具体显示它想要什么。所以我尝试了最明显的语法(在 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
参数可能无效。
我是 Cython 的新手,但通过遵循此 basic guide from the official docs:
它只说: “Cython 有一种方法可以可视化与 Python 对象和 Python 的 C-API 发生交互的位置。为此,将 annotate=True 参数传递给 cythonize()。它生成一个 HTML 文件。"
我很惊讶我不能只 Google 这个问题,或者 Whosebug 上没有人问过这个问题。但我不知道如何让它工作。它没有具体显示它想要什么。所以我尝试了最明显的语法(在 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
参数可能无效。