致命错误:找不到numpy / arrayobject.h文件或目录

11
我受到限制,无法分享太多信息,因为我正在从Ubuntu 14.04移植到16.04的大量代码堆栈中工作。这似乎应该很简单,但是我仍然在努力解决问题。我的源文件中引用了#include <numpy/arrayobject.h>,但它找不到我所需的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

制作
$ make --version
GNU Make 4.1
Built for x86_64-pc-linux-gnu

g++

$ g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609

升级到

# 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.

python

$ python --version
Python 2.7.12

Some environment variables

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

错误

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

我的源文件

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...

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

root@deploy:/home#  find / -name arrayobject.h
/usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy/arrayobject.h

请告诉我如何改进问题。欢迎提供指导或建议。

更新

$ ls -l /usr/include/numpy
ls: cannot access '/usr/include/numpy': No such file or directory

解决方案

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

相关链接:https://dev59.com/l3E95IYBdhLWcg3wRL0t - Bernhard
2个回答

21

我在一个部分损坏的Debian安装中经历了同样的问题。

通过重新建立符号链接,我解决了这个错误。

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


2
在Alpine Linux上使用Python 3.7时遇到了类似的问题。/usr/lib/python3.7/site-packages/numpy/core/路径下没有include文件夹,请问有什么建议吗? - xiaolong
2
安装Python的开发包。 - Jens Munk
对于Manjaro,以下命令可以帮助解决问题:sudo ln -s /usr/lib64/python3.10/site-packages/numpy/core/include/numpy/ /usr/include/numpy - vindarmagnus

11

你是如何安装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

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


1
这个解决方案在我的情况下有效,因为我使用conda安装了numpy。 - Tai Christian

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接