【问题标题】:fatal error: numpy/arrayobject.h: No such file or directory致命错误:numpy/arrayobject.h:没有这样的文件或目录
【发布时间】:2017-12-06 22:05:25
【问题描述】:

我可以分享的内容有限,因为这是我从 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 --version
Python 2.7.12

一些环境变量

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

【问题讨论】:

    标签: python c++ numpy g++


    【解决方案1】:

    我在部分损坏的 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 文件夹,有什么指针吗?
    • 安装python的开发包
    【解决方案2】:

    你是如何安装 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,然后你可以相应地手动创建一个软链接。

    【讨论】:

    • 此解决方案适用于我的情况,因为我使用 conda 安装了 numpy。
    猜你喜欢
    • 2021-02-14
    • 2013-01-17
    • 1970-01-01
    • 2017-05-09
    • 2021-05-15
    • 2014-10-31
    • 2022-01-11
    • 2021-09-19
    相关资源
    最近更新 更多