4

I'm trying to install the fastcluster Python library, but I'm running into a compilation error.

$ pip install fastcluster

produces the following output:

Collecting fastcluster
  Using cached fastcluster-1.1.17.tar.gz
Building wheels for collected packages: fastcluster
  Running setup.py bdist_wheel for fastcluster
  Complete output from command /home/ruser/dedupe/venv/bin/python -c "import setuptools;__file__='/tmp/pip-build-9ejthV/fastcluster/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /tmp/tmpXVyTyspip-wheel-:
  Version: 1.1.17
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-2.7
  copying fastcluster.py -> build/lib.linux-x86_64-2.7
  running build_ext
  building '_fastcluster' extension
  creating build/temp.linux-x86_64-2.7
  creating build/temp.linux-x86_64-2.7/src
  x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/fastcluster_python.cpp -o build/temp.linux-x86_64-2.7/src/fastcluster_python.o
  cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
  src/fastcluster_python.cpp:38:31: fatal error: numpy/arrayobject.h: No such file or directory
   #include <numpy/arrayobject.h>
                                 ^
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for fastcluster
Failed to build fastcluster
Installing collected packages: fastcluster
  Running setup.py install for fastcluster
    Complete output from command /home/ruser/dedupe/venv/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-9ejthV/fastcluster/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-85ovHC-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/ruser/dedupe/venv/include/site/python2.7/fastcluster:
    Version: 1.1.17
    running install
    running build
    running build_py
    running build_ext
    building '_fastcluster' extension
    x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/fastcluster_python.cpp -o build/temp.linux-x86_64-2.7/src/fastcluster_python.o
    cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
    src/fastcluster_python.cpp:38:31: fatal error: numpy/arrayobject.h: No such file or directory
     #include <numpy/arrayobject.h>
                                   ^
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

    ----------------------------------------
Command "/home/ruser/dedupe/venv/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-9ejthV/fastcluster/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-85ovHC-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/ruser/dedupe/venv/include/site/python2.7/fastcluster" failed with error code 1 in /tmp/pip-build-9ejthV/fastcluster

What would cause this? Something about setting include directories?

ali_m
  • 71,714
  • 23
  • 223
  • 298
JonNYC
  • 43
  • 3
  • Might be related to this: http://stackoverflow.com/q/14657375/1461210 – ali_m Jul 15 '15 at 19:43
  • Try the following: download the package without installing it (`pip install fastcluster --download='.'`), untar it, edit `setup.py` so that the `Extension` in `ext_modules` has the following keyword argument: `include_dirs=[numpy.get_include()]`, then install it using `python setup.py install` – ali_m Jul 15 '15 at 19:50
  • Thanks for quick reply - tried that but when I run python setup.py install I get: NameError: name 'numpy' is not defined – JonNYC Jul 15 '15 at 20:14
  • You need to `import numpy` – ali_m Jul 15 '15 at 20:14
  • Ah yes sorry missed obvious, that seemed to work to get fastcluster installed! Let me try some tests and work on the rest. – JonNYC Jul 15 '15 at 20:35
  • Totally working and it was the other issue you linked to, thanks again and apologies for not finding on my own. – JonNYC Jul 15 '15 at 21:03
  • No worries - I'll re-write my comment as an answer – ali_m Jul 15 '15 at 21:18
  • This problem has been fixed in fastcluster version 1.1.18. – Daniel Jul 16 '15 at 13:12

1 Answers1

3

The issue you're seeing with installing fastcluster is related to this previous question - the compiler is not looking in the correct directory to find the numpy headers. You can use more or less the same solution as given in the accepted answer:

  1. Download and untar the source for fastcluster

    $ pip install fastcluster --download='.'
    $ tar -xzf fastcluster-1.1.17.tar.gz
    $ cd fastcluster-1.1.17/
    
  2. Edit the setup.py file to add the output of numpy.get_include() to the include_dirs= argument for the Extension:

    import numpy
    
    ...
    
    ext_modules=[Extension('_fastcluster',                                     
                           ['src/fastcluster_python.cpp'],                     
                           extra_compile_args=['/EHsc'] if os.name=='nt' else [],
                           include_dirs=[numpy.get_include()]
                           )]
    
  3. Install fastcluster:

    $ python setup.py install
    
  4. Let the fastcluster maintainer know that his package is broken :-)

Community
  • 1
  • 1
ali_m
  • 71,714
  • 23
  • 223
  • 298
  • 2
    Step 4 should not be optional! Thanks to Forest Gregg (U Chicago) for notifying me about the problem, and thanks to ali_m for the solution. I fixed it in fastcluster version 1.1.18. – Daniel Jul 16 '15 at 13:13
  • Can your approach also work in the case here http://unix.stackexchange.com/q/294979/16920 ? – Léo Léopold Hertz 준영 Jul 11 '16 at 14:47