Python 安装fastcluster库时遇到问题,numpy include错误

Python 安装fastcluster库时遇到问题,numpy include错误,python,python-2.7,numpy,Python,Python 2.7,Numpy,我试图安装fastclusterPython库,但遇到编译错误 $ 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 fr

我试图安装
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
收集fastcluster
使用缓存的fastcluster-1.1.17.tar.gz
为收集的包构建控制盘:fastcluster
为fastcluster运行setup.py bdist_控制盘
从命令/home/ruser/dedupe/venv/bin/python-c“导入setuptools;uu文件uu=”/tmp/pip-build-9ejthV/fastcluster/setup.py';exec(编译(打开(u文件uuu)。读取().replace('\r\n','\n'),u文件uu,'exec')))”bdist u-wheel-d/tmp/tmpxytyspip-wheel-:
版本:1.1.17
运转的车轮
运行构建
运行build\u py
创建构建
创建build/lib.linux-x86_64-2.7
正在复制fastcluster.py->build/lib.linux-x86_64-2.7
运行build_ext
正在生成“\u fastcluster”扩展
创建build/temp.linux-x86_64-2.7
创建build/temp.linux-x86_64-2.7/src
x86_64-linux-gnu-gcc-pthread-fno严格别名-DNDEBUG-g-fwrapv-O2-Wall-Wstrict原型-fPIC-I/usr/include/python2.7-c src/fastcluster_python.cpp-o build/temp.linux-x86_64-2.7/src/fastcluster_python.o
Cc1Puls:警告:命令行选项'WraseTrimeType '对于C/Objc有效,但不适用于C++(默认启用)
src/fastcluster_python.cpp:38:31:致命错误:numpy/arrayobject.h:没有这样的文件或目录
#包括
^
编译终止。
错误:命令“x86_64-linux-gnu-gcc”失败,退出状态为1
----------------------------------------
为fastcluster构建控制盘失败
未能生成fastcluster
安装收集的软件包:fastcluster
正在为fastcluster运行setup.py安装
从命令/home/ruser/dedupe/venv/bin/python-c“导入setuptools,tokenize;_文件_=”/tmp/pip-build-9ejthV/fastcluster/setup.py';exec(compile(getattr(tokenize,'open',open)(__u文件_)).read().replace('\r\n','\n'),_u文件u,'exec')))完成输出”安装--record/tmp/pip-85ovHC-record/install-record.txt--外部管理的单一版本--编译--install headers/home/ruser/dedupe/venv/include/site/python2.7/fastcluster:
版本:1.1.17
正在运行的安装
运行构建
运行build\u py
运行build_ext
正在生成“\u fastcluster”扩展
x86_64-linux-gnu-gcc-pthread-fno严格别名-DNDEBUG-g-fwrapv-O2-Wall-Wstrict原型-fPIC-I/usr/include/python2.7-c src/fastcluster_python.cpp-o build/temp.linux-x86_64-2.7/src/fastcluster_python.o
Cc1Puls:警告:命令行选项'WraseTrimeType '对于C/Objc有效,但不适用于C++(默认启用)
src/fastcluster_python.cpp:38:31:致命错误:numpy/arrayobject.h:没有这样的文件或目录
#包括
^
编译终止。
错误:命令“x86_64-linux-gnu-gcc”失败,退出状态为1
----------------------------------------
命令“/home/ruser/dedupe/venv/bin/python-c”导入setuptools,标记化__文件\ \='/tmp/pip-build-9ejthV/fastcluster/setup.py';exec(compile(getattr(tokenize,'open',open)('uuuuu file_uuu.).read().replace('\r\n','\n'),'uuuuu file_uuu,'exec'))“安装--record/tmp/pip-85ovHC-record/install-record.txt--外部管理的单一版本--编译--安装头/home/ruser/dedupde/venv/include/site/python2.7/fastcluster”失败,错误代码为/tmp/pip-build-9ejthV/fastcluster中的1

这是什么原因造成的?有关设置包含目录的内容?

您在安装
fastcluster
时遇到的问题与此相关-编译器没有在正确的目录中查找numpy头。您可以使用与公认答案中给出的解决方案大致相同的解决方案:

  • 下载并卸载
    fastcluster

    $ pip install fastcluster --download='.'
    $ tar -xzf fastcluster-1.1.17.tar.gz
    $ cd fastcluster-1.1.17/
    
  • 编辑
    setup.py
    文件,将
    numpy.get\u include()
    的输出添加到
    扩展名的
    include\u dirs=
    参数中:

    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
    
  • 让他知道他的包裹坏了:-)


  • 可能与此相关:请尝试以下操作:在不安装包的情况下下载包(
    pip install fastcluster--download='.
    ),卸载包,编辑
    setup.py
    ,以便
    ext\u modules
    中的
    扩展名
    具有以下关键字参数:
    include\u dirs=[numpy.get\u include()]
    ,然后使用
    python setup.py install安装它
    感谢您的快速回复-尝试过了,但当我运行python setup.py安装时,我得到了:name错误:name'numpy'未定义您需要
    import numpy
    啊,是的,很抱歉,这似乎可以安装fastcluster!让我尝试一些测试,并在其余的工作。第4步不应该是可选的!感谢Forest Gregg(U Chicago)通知我这个问题,也感谢ali_m提供的解决方案。我在fastcluster版本1.1.18中修复了它。您的方法在这里的情况下也可以工作吗?