question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

docs error: cythonize(include_path=x) does not set C include path

See original GitHub issue

The documentation in compilation.rst claims that

cythonize(extensions, include_path=[numpy.get_include()])

adds the numpy include path to the include file search path used by the compiler. This has been quoted many times and the documented feature is used by many packages, although with zero effect: include_path only adds to the search path used by Cython to find pyx and pxd files.

Some alternative ways to address this:

  1. Change docs to match code by removing the misleading section.
  2. Change code to match docs by adding the feature.
  3. Change docs and code to use cython(include_dirs=[]) as a way for globally specifying C include paths.
  4. Change it all to have cython_include_dirs and c_include_dirs (or path).

3 has the benefit that code using include_path will continue to function as before (no effect on C include path), while making the feature people have obviously been expecting available. The term include_dir would then consistently (albeit not obviously) refer to the C includes and the term include_path to the Cython includes.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:15
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

11reactions
makmanalpcommented, Jul 2, 2018

Having just hit this and spent a while trying to figure out how to work around it, I’d like to voice my support for solution #2 (I can’t see the harm, but I don’t know much about this, so …), but also just as an interim measure doing #1 or some variant to fix the docs, which is explicitly claiming something with numpy that doesn’t work. I know I’m not the only one to be mislead by this, just by how very often this issue shows up:

https://www.google.com/search?q=numpy%2Farrayobject.h'+file+not+found&oq=numpy%2Farrayobject.h'+file+not+found&aqs=chrome..69i57j69i58.427j0j7&sourceid=chrome&ie=UTF-8

For posterity, my interim solution was to pass in my own Extension() to cythonize, which does kinda take away from the benefit of having cythonize in the first place IMHO.

from setuptools import setup, Extension
from Cython.Build import cythonize
import numpy as np

setup(
    name='xyz',
    ext_modules=cythonize(
        Extension(
            "xyz",
            sources=[a/b.pyx"],
            include_dirs=[np.get_include()]
        )
    ),
    install_requires=["numpy"]
)
3reactions
native-apicommented, Oct 31, 2016

I’d say it’s not a doc bug but a Cython bug. cythonize produces an Extension object which has include_dirs as one of its attributes. cythonize should be setting this attribute.

>>> from Cython.Build import cythonize
>>> import numpy as np
>>> e=cythonize("test.pyx",include_path=[np.get_include()])
>>> len(e)
1
>>> e[0].include_dirs
[]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cython compilation error with include_path as a keyword in ...
c (346) : fatal error C1083: Cannot open include file: 'numpy/arrayobject.h': No such file or directory. I am using Python 3.3 64-bit on...
Read more >
Source Files and Compilation - Cython's Documentation
A .pyx (or .py ) file is compiled by Cython to a .c file. ... static_libs/include/ but this path isn't always fixed and...
Read more >
How to Fix Include Path Error in C/C++ Files using ... - YouTube
How to fix vscode error : # include errors detected. Please update your includePath. ... Your browser can't play this video.
Read more >
Compilation — Cython 0.21 documentation - API Manual
The .c file is compiled by a C compiler to a .so file (or a .pyd file on ... same directory and your...
Read more >
Importing a cython module from another module
from cythonAnimal.cat import Cat #Fail here with the error below ... I saw somewhere that setup.py should be in the root directory, not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found