python-pillow / Sane

Python interface to the SANE scanner and frame grabber
Other
54 stars 19 forks source link

Build failure with NumPy available #5

Closed Arfrever closed 9 years ago

Arfrever commented 9 years ago

After manually working around https://github.com/python-pillow/Pillow/issues/1076, the following build failure occurs if NumPy is installed:

$ python3.4 setup.py build
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.4
copying sane.py -> build/lib.linux-x86_64-3.4
running build_ext
building '_sane' extension
creating build/temp.linux-x86_64-3.4
x86_64-pc-linux-gnu-gcc -pthread -fPIC -DWITH_NUMPY -I/usr/include/python3.4/Imaging -I/usr/include/python3.4 -c _sane.c -o build/temp.linux-x86_64-3.4/_sane.o -Wunused-function
_sane.c:972:32: fatal error: numpy/ndarraytypes.h: No such file or directory
 #include "numpy/ndarraytypes.h"
                                ^
compilation terminated.
error: command 'x86_64-pc-linux-gnu-gcc' failed with exit status 1
$ python3.4 -c 'import numpy; print(numpy.get_include())'
/usr/lib64/python3.4/site-packages/numpy/core/include

Fix:

--- setup.py
+++ setup.py
@@ -4,6 +4,7 @@

 defs = []
 extra_compile_args =  []
+include_dirs = [os.path.join(distutils.sysconfig.get_python_inc(), "Imaging")]
 try:
     import numarray
     defs.append(('WITH_NUMARRAY',None))
@@ -13,13 +14,12 @@
     import numpy
     defs.append(('WITH_NUMPY',None))
     extra_compile_args.append('-Wunused-function')
+    include_dirs.append(numpy.get_include())
 except ImportError:
     pass

 sane = Extension('_sane',
-                 include_dirs = [
-                     os.path.join(distutils.sysconfig.get_python_inc(), "Imaging")
-                 ],
+                 include_dirs = include_dirs,
                  libraries = ['sane'],
                  define_macros = defs,
                  extra_compile_args = extra_compile_args,
manisandro commented 9 years ago

Hi, thanks for reporting. Can you create a pull request with the patch?