致命错误:numpy / arrayobject.h:没有此类文件或目录

zab*_*mba 4 c++ python numpy g++

我的共享能力受到限制,因为这是我从Ubuntu 14.04移植到16.04的大量代码的一部分。

这应该是微不足道的,但是我却为此而苦苦挣扎。找不到numpy/arrayobject.h我在源文件中引用的#include <numpy/arrayobject.h>

我将尽力分享尽可能多的东西,看看是否有人可以指导我解决问题。

的Ubuntu

$ lsb_release -a 
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.2 LTS
Release:    16.04
Codename:   xenial
Run Code Online (Sandbox Code Playgroud)

使

$ make --version
GNU Make 4.1
Built for x86_64-pc-linux-gnu
Run Code Online (Sandbox Code Playgroud)

g ++

$ g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
Run Code Online (Sandbox Code Playgroud)

升级到

# g++ --version
g++ (Ubuntu 5.4.1-2ubuntu1~16.04) 5.4.1 20160904
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Run Code Online (Sandbox Code Playgroud)

蟒蛇

$ python --version
Python 2.7.12
Run Code Online (Sandbox Code Playgroud)

一些环境变量

PYTHON       /usr/bin/python2.7
ARCH         x86_64
OS           Linux
VERSION      4.4.071generic
PLATFORM     linux2
HOSTNAME     deploy
USER         myUser
WUSS_BUILD   NO
CCVER        gcc
PYLIBDIR     build.x86_64-linux2
LIBDIR       build.x86_64-linux2
BINDIR       build.x86_64-linux2
ODIR         build.x86_64-linux2-gcc
STATICLIBDIR build-static.x86_64-linux2
Run Code Online (Sandbox Code Playgroud)

错误

make命令导致

+++ Compile mycore/boost_numpy.cc to build.x86_64-linux2-gcc
anycore/boost_numpy.cc:2:31: fatal error: numpy/arrayobject.h: No such file or directory
Run Code Online (Sandbox Code Playgroud)

我的源文件

user@deploy:~/my-linux$ vim mycore/boost_numpy.cc

#include "anycore/boost_python_headers.h"
#include <numpy/arrayobject.h>           <====== DECLARATION
#include <numpy/ufuncobject.h>        
#include "mycore/boost_numpy.h"
#include "mycore/numerical.h"
#include "mycore/vec3.h"

using namespace boost::python;

PyObject *
read_numeric_file_ficii(FILE *fp, int ncols, char arrtype, int headlines, int taillines)
{
  if (!(arrtype=='d' || arrtype=='f' || arrtype=='i')) {
    PyErr_SetString(PyExc_ValueError, "Unknown array type for read_numeric_file");
    return NULL;
  }
...FILTERED...
Run Code Online (Sandbox Code Playgroud)

numpy/arrayobject.h磁盘上的声明文件

root@deploy:/home#  find / -name arrayobject.h
/usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy/arrayobject.h
Run Code Online (Sandbox Code Playgroud)

请让我知道如何改善这个问题。方向或指针是最欢迎的

更新

$ ls -l /usr/include/numpy
ls: cannot access '/usr/include/numpy': No such file or directory
Run Code Online (Sandbox Code Playgroud)

解决

sudo ln -s  /usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy /usr/include/numpy
Run Code Online (Sandbox Code Playgroud)

Jen*_*unk 8

我在部分中断的Debian安装中遇到了相同的行为。

我通过重新建立符号链接来修复错误

sudo ln -s /usr/lib/python2.7/dist-packages/numpy/core/include/numpy /usr/include/numpy

  • 在使用 Python 3.7 的 Alpine Linux 上也有类似的问题。`/usr/lib/python3.7/site-packages/numpy/core/` 中没有 `include` 文件夹,有任何指针吗? (2认同)
  • 安装python的开发包 (2认同)

Min*_*ine 6

你是如何安装numpy的?

如果您python-numpy正确安装,例如通过sudo apt-get install python-numpy,您将/usr/include/numpy链接到正确的路径:

$ ls -l /usr/include/numpy
lrwxrwxrwx 1 root root 55 Sep 17  2014 /usr/include/numpy -> ../lib/python2.7/dist-packages/numpy/core/include/numpy
Run Code Online (Sandbox Code Playgroud)

看起来您可以手动构建 numpy,然后您可以相应地手动创建软链接。