在安装fastcluster库时遇到问题,numpy包含错误

时间:2015-07-15 19:26:16

标签: python python-2.7 numpy

我正在尝试安装fastcluster Python库,但我遇到了编译错误。

$ pip install fastcluster

产生以下输出:

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

这会导致什么?设置包括目录?

1 个答案:

答案 0 :(得分:3)

您在安装fastcluster时遇到的问题与this previous question有关 - 编译器未查找正确的目录以查找numpy标头。您可以使用与接受的答案中给出的解决方案相同的解决方案:

  1. 下载并解压fastcluster

    的来源
    $ pip install fastcluster --download='.'
    $ tar -xzf fastcluster-1.1.17.tar.gz
    $ cd fastcluster-1.1.17/
    
  2. 修改setup.py文件,将numpy.get_include()的输出添加到include_dirs=的{​​{1}}参数中:

    Extension
  3. 安装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
  4. fastcluster maintainer知道他的包裹坏了: - )