Cython: "Fatal Error: Numpy/Arrayobject.H: No Such File or Directory"

Cython: fatal error: numpy/arrayobject.h: No such file or directory

In your setup.py, the Extension should have the argument include_dirs=[numpy.get_include()].

Also, you are missing np.import_array() in your code.

--

Example setup.py:

from distutils.core import setup, Extension
from Cython.Build import cythonize
import numpy

setup(
ext_modules=[
Extension("my_module", ["my_module.c"],
include_dirs=[numpy.get_include()]),
],
)

# Or, if you use cythonize() to make the ext_modules list,
# include_dirs can be passed to setup()

setup(
ext_modules=cythonize("my_module.pyx"),
include_dirs=[numpy.get_include()]
)

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

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

How do I resolve this make fatal error: numpy/arrayobject.h: No such file or directory?

Without seeing the complete Makefile it's hard to be sure what's wrong, but this line looks like it can't possibly be correct:

$(shell set(PYTHON_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS} /usr/local/lib/python3.5/dist-packages/numpy/core/include))

In GNU make, $(shell ...) runs sh -c "..." [technically, $(SHELL) -c "...") and evaluates to whatever that command prints on its stdout. set(...) is not valid sh syntax, and also, the stuff inside $(shell ...) cannot change Make variables. I would expect this line to print an error message as part of the make log, something like

sh: 1: Syntax error: word unexpected (expecting ")")

and otherwise have no effect.

Assuming the goal here is to append /usr/local/lib/python3.5/dist-packages/numpy/core/include to the value of the Make variable PYTHON_INCLUDE_DIRS, the way to do that is with +=:

PYTHON_INCLUDE_DIRS += /usr/local/lib/python3.5/dist-packages/numpy/core/include

The rules you quoted don't directly make use of this variable, but I suspect there may be a reference to it hiding inside $(COMMON).

cimport gives fatal error: 'numpy/arrayobject.h' file not found

Ok, as has been pointed out above, similar questions have been asked before.
Eg: Make distutils look for numpy header files in the correct place.
I got my code to work by using a setup file with the line

include_dirs = [np.get_include()], 

As in:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import numpy as np

ext = [Extension( "cy_test", sources=["cy_test.pyx"] )]

setup(
name = "testing",
cmdclass={'build_ext' : build_ext},
include_dirs = [np.get_include()],
ext_modules=ext
)

I haven't yet tried using pyximport so I'm not sure whether another fix is required for that.

C++: numpy/arrayobject.h: No such file or directory CMake VSCode

I'm not seeing a lot of documentation for FindPython3 or FindPython for CMake 3.0.0 so I'm not sure if that module included before CMake 3.12.0. Version 3.12 is the first occurence I could find in the cmake documentation.

The most likely thing is that you just need to change to using

cmake_minimum_required(VERSION 3.12.0)

Updating your CMake version is probably the simplest solution but again you might have good reason to limit the version and just telling you to update isn't much of a solution.

Another hackier solution would be to use one of the paths from Python_INCLUDE_DIRS or Python_LIBRARIES do some relative pathing from there. Something like

set(numpy_INCLUDE_DIR "${Python_INCLUDE_DIR}/../site-packages/numpy
/core/include")
include_directories(${Python_INCLUDE_DIRS} ${numpy_INCLUDE_DIR})

This however assumes that your python directories are setup as if they came from a python distribution and would in turn assume that everyone that uses this also has a distribution with the same file structure.

fatal error: 'arrayobject.h' file not found when using pyenv

I used pyenv to install Python 3.6-dev on Linux Mint 19.2 and I found two problems during installation pypesq:


1. It couldn't find arrayobject.h from module numpy

I used answer from Ubuntu forum fatal error: numpy/arrayobject.h: No such file or directory

I had to find folder with arrayobject.h and add it to environment variable CFLAGS so later C/C++ compiler will use it to find arrayobject.h- ie. (directly in terminal)

export CFLAGS="-I /usr/local/lib/python3.7/dist-packages/numpy/core/include/numpy/ $CFLAGS"

I was installing pypesq for Python 3.6-dev but I used path to numpy installed in Python 3.7 and there was no problem.

BTW: To find it I used shell command locate which is not standard command but it works much faster then find


2. It couldn't find pesq.h

Instead of using module from pip server I used code from GitHub which was updated yesterday

pipenv install https://github.com/vBaiCai/python-pesq/archive/master.zip

After that I could import it in Python 3.6-dev but I didn't test if it works correctly.



Related Topics



Leave a reply



Submit