Problems installing the fastcluster library, numpy include error

I am trying to install the Python library fastcluster, but I encountered a compilation error.

$ pip install fastcluster

outputs the following result:

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 can cause this? Something about customizing include directories?

+4
source share
1 answer

The problem you see during installation fastclusteris related to this previous question - the compiler is not looking in the right directory to find numpy headers. You can use more or less the same solution as in the accepted answer:

  • Download and unlock source for fastcluster

    $ pip install fastcluster --download='.'
    $ tar -xzf fastcluster-1.1.17.tar.gz
    $ cd fastcluster-1.1.17/
    
  • Edit the file setup.pyto add output numpy.get_include()to the argument include_dirs=for 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()]
                           )]
    
  • fastcluster:

    $ python setup.py install
    
  • fastcluster , : -)

+3

Source: https://habr.com/ru/post/1598110/


All Articles