I am writing a small C function that is supposed to accelerate some compute intensive portions of a larger application that I have in Python. Naturally I have written a wrapper that ensures that my C code can talk seamlessly with my Python numpy arrays. All is well and I am using the following setup.py
from distutils.core import setup, Extension
import numpy
module1 = Extension('my_wrapper',
sources = ['my_c_file.c'],
include_dirs=[numpy.get_include()],
extra_compile_args = ['-fopenmp'],
extra_link_args = ['-lgomp'])
setup(name = 'my_wrapper',
version = '1.0',
description = 'Some description here',
ext_modules = [module1])
Everything works when I compile this with the command python3 setup.py install
and the code behaviour is as expected but I am getting the following warning,
warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
#warning "Using deprecated NumPy API, disable it by " \
^
Although this is just a warning, I would still like to avoid this if I can. Any ideas on how to do that?
This is a known issue, and it stems from the fact that Cython historically has supported very old numpy
versions. As cython
's doc mentions:
Despite this, you will still get warnings like the following from the compiler, because Cython is using a deprecated Numpy API:
.../include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
For the time being, it is just a warning that you can ignore.
However, there's work in progress in several pull requests and the parent issue tracking the progress can be found here.
Soon these warnings will be gone.
Until this is resolved upstream as mentioned by adrin, I found a way to insert the preprocessor symbol NPY_NO_DEPRECATED_API
into the setup.py
code so that the warning will be suppressed. Add the keyword define_macros=[args]
to your Extension
. Just putting it in your .h, .cpp, or .pyx files will not help because the auto-generated project .cpp file will not see the preprocessor defines.
https://docs.python.org/2.0/dist/node13.html
Specifically for OP's case:
module1 = Extension('my_wrapper', sources = ['my_c_file.c'],
include_dirs=[numpy.get_include()],
extra_compile_args = ['-fopenmp'],
extra_link_args = ['-lgomp']),
define_macros=[('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION')])
This will add -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION
to the compile line.
Fair warning: doing this may enable several new warnings that were suppressed because it was maintaining compatibility with old versions.
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