14

I'm new to Cython, but got it working by following this basic guide from the official docs:

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."

I'm very surprised that I couldn't just Google this one or that no one on stackoverflow has asked this. 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):

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.

I am on windows using the latest version of Python 3.7 with Cython 0.29.12.

https://cython.readthedocs.io/en/latest/src/tutorial/cython_tutorial.html

7
  • 4
    This probably because nothing is built: sadly changing setup.py doesn't lead to a complete rebuild. You need to add --force, i.e. python setup.py build_ext --inplace --force, then html is next to pyx-file.
    – ead
    Commented Jul 8, 2019 at 5:06
  • Pretty sure that isn't the problem. I did notice that (thanks for the --force switch!) but I just deleted the build and it started fresh. Same result. No HTML. Commented Jul 8, 2019 at 6:16
  • I tried adding: import Cython.Compiler.Options Cython.Compiler.Options.annotate = True No effect Commented Jul 8, 2019 at 6:35
  • 1
    github.com/cython/cython/issues/3036 Commented Jul 8, 2019 at 6:51
  • 3
    setup.py --force did not work for me. However, removing the generated out.c file made the annotate=True work which created the .html file.
    – mateuszb
    Commented Aug 12, 2019 at 20:11

3 Answers 3

17

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)
)
9

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.

--force argument may not work.

7

You can try to remove the generated c or cpp file. If there's no change in pyx, cython won't try to repeat the build. I don't know how cython tracks the build dependencies. I guess it's similar to how make works.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.