fatal error: numpy/arrayobject.h: No such file or directory
Asked Answered
M

3

11

I am limited on what I can share as this is part of a huge stack of code that I am porting from Ubuntu 14.04 to 16.04.

It should be trivial, but somehow I am struggling with this. It doesn't find numpy/arrayobject.h that I am referencing in my source file with #include <numpy/arrayobject.h>

I will try to share as much as I can, see if someone can guide me through a resolution.

Ubuntu

$ lsb_release -a 
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.2 LTS
Release:    16.04
Codename:   xenial

make

$ 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

upgraded to

# 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

Error

The make command leads to

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

My source file

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

Declaration file numpy/arrayobject.h on disk

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

Please let me know how I can improve the question. Directions or pointers are most welcome

UPDATE

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

RESOLVED WITH

sudo ln -s  /usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy /usr/include/numpy
Militarize answered 3/7, 2017 at 15:8 Comment(1)
Related: #2380398Certify
M
21

I have experienced the same behavior on a partly broken Debian installation.

I fixed the error by reestablishing a symbolic link

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

Moonstone answered 5/7, 2017 at 21:3 Comment(3)
Having similar issue on Alpine Linux with Python 3.7. There isn't an include folder inside /usr/lib/python3.7/site-packages/numpy/core/, any pointers?Qua
Install the dev package for pythonMoonstone
for manjaro the following helped sudo ln -s /usr/lib64/python3.10/site-packages/numpy/core/include/numpy/ /usr/include/numpyBride
I
11

How did you install numpy?

If you install python-numpy correctly, e.g. by sudo apt-get install python-numpy, you will have /usr/include/numpy linked to the correct path:

$ 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

It looks like you may build your numpy manually, then you can manually create a soft link accordingly.

Instruct answered 6/7, 2017 at 8:22 Comment(1)
This solution works in my case because I installed numpy using conda.Obligatory
P
0

use: #include <../Lib/site-packages/numpy/core/include/numpy/arrayobject.h> replace.

Padnag answered 1/4 at 14:2 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Cuyler

© 2022 - 2024 — McMap. All rights reserved.