Please what is the simplest / most elegant way of how to determine correct paths for numpy include as they are present on target system ? And then use it by make command ? At the moment I am using
gcc ... -I/usr/include/python2.7/ -I/usr/lib/python2.7/site-packages/numpy/core/include/numpy/
and I would like to have those two includes automatically selected based on system on which the build is perfromed on.
It seems like I can get the second include like this:
python -c "import numpy; print numpy.__path__[0] + 'core/include/numpy/'"
but I am not sure about the first one and even if I was I still wouldn't be sure how to best use it from makefile (in an easy / elegant way)
NumPy is written in C, and executes very quickly as a result. By comparison, Python is a dynamic language that is interpreted by the CPython interpreter, converted to bytecode, and executed. While it's no slouch, compiled C code is always going to be faster.
C extensions are C code that can be compiled and linked to a shared library that can be imported like any Python module and you can call specified C routines like they were Python functions.
I believe the vast majority of NumPy and SciPy is written in C and wrapped in Python for ease of use. It probably depends what you're doing in any of those languages as to how much overhead there is for a particular application.
numpy.get_include()
is the easiest/best way to get the includes. If your C extension module uses numpy then in Extension you have to use include_dirs=[numpy.get_include()]
. Why numpy.get_include()
doesn't seem to have any documentation I don't know.
Then you can do as user1056255 suggests but just a bit better...
CFLAGS = $(shell python-config --includes) $(shell python -c "import numpy; print '-I' + numpy.get_include()")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With