Fatal error: numpy/arrayobject.h: No such file or directory while building package

I’ve been trying to write a nix package definition for this GNU Radio library I wrote a while ago, but I’ve been getting this error
/build/source/python/bindings/python_bindings.cc:13:10: fatal error: numpy/arrayobject.h: No such file or directory
saying it can’t find a header file from numpy, even though I’ve included pythonPackages.numpy in propagatedBuildInputs.
Heres the code:

{ lib
, stdenv
, fetchFromGitLab
, cmake
, pkg-config
, cppunit
, boost175
, log4cpp
, python
, doxygen
, gnuradio
, mpir
, volk
, gmp
, liquid-dsp
, icu
, pythonPackages
}:

stdenv.mkDerivation {
  pname = "gr-librelora";
  version = "1.3";
  src = fetchFromGitLab {
    owner = "jpsimas";
    repo = "librelora";
    rev = "v1.3";
    sha256 = "1g0sgasjngzwd9pgbb3bnswy6c0k29j0rld0k862w2zjsg52rwra";
  };
  disabledForGRafter = "3.9";

  nativeBuildInputs = [
    cmake
    pkg-config
    doxygen
    pythonPackages.pybind11
  ];

  buildInputs = [
    cppunit
    log4cpp
    boost175
    gnuradio
    mpir
    volk
    gmp
    liquid-dsp
    icu
  ];

  propagatedBuildInputs  = [
    pythonPackages.numpy
  ];

  meta = with lib; {
    description = "GNURadio Based LoRa PHY receiver and transmitter implementations";
    homepage = "https://gitlab.com/jpsimas/librelora";
    license = licenses.gpl3Plus;
    platforms = platforms.linux ++ platforms.darwin;
    maintainers = with maintainers; [];
  };
}

Have I included numpy in the wrong way or is the problem somewhere else? I’ve successfully built this using guix before, so there’s no problem with the library itself.

Thanks for your help

I managed to compile it. I structured this way:

❯ tree
.
├── default.nix
└── librelora
    └── default.nix

The content of librelora/default.nix:

{ lib
, stdenv
, fetchFromGitLab
, cmake
, pkg-config
, cppunit
, boost
, log4cpp
, python
, doxygen
, gnuradio
, mpir
, volk
, gmp
, liquid-dsp
, icu
, spdlog
, git
, thrift
}:

stdenv.mkDerivation {
  pname = "gr-librelora";
  version = "1.3";
  src = fetchFromGitLab {
    owner = "jpsimas";
    repo = "librelora";
    rev = "v1.3";
    sha256 = "1g0sgasjngzwd9pgbb3bnswy6c0k29j0rld0k862w2zjsg52rwra";
  };

  nativeBuildInputs = [
    cmake
    pkg-config
    doxygen
    thrift
    python.pkgs.pybind11
    # python.pkgs.pygccxml
    # python.pkgs.thrift
  ] ++ gnuradio.pythonPkgs;

  buildInputs = [
    cppunit
    log4cpp
    boost
    gnuradio
    mpir
    volk
    gmp
    liquid-dsp
    icu
    spdlog
    git
  ];

  propagatedBuildInputs  = [
    gnuradio.python.pkgs.numpy
  ];

  meta = with lib; {
    description = "GNURadio Based LoRa PHY receiver and transmitter implementations";
    homepage = "https://gitlab.com/jpsimas/librelora";
    license = licenses.gpl3Plus;
    platforms = platforms.linux ++ platforms.darwin;
    maintainers = with maintainers; [];
  };
}

And default.nix:

{ pkgs ? import <nixpkgs> { }
}:

with pkgs;
with pkgs.lib;
let
  packages = rec {
    librelora = gnuradio.pkgs.callPackage ./librelora {
      inherit gnuradio;
      inherit (gnuradio) python boost;
      stdenv = gcc10Stdenv; # It's not compiling with last gcc version
    };

    shell = mkShell {
      name = "manolo";
      buildInputs = [
        librelora
        gnuradio.python
      ];
    };
  };
in
packages

Calling this way:

nix-shell default.nix -A shell

To have shell with the python module. But I’m having this problem:

❯ python
Python 3.9.12 (main, Mar 23 2022, 21:36:19) 
[GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import LibreLoRa
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/nix/store/ikc7pszaqr2m5a5ybz5a0kspmnm4hs45-gr-librelora-1.3/lib/python3.9/site-packages/LibreLoRa/__init__.py", line 30, in <module>
    from .LibreLoRa_python import *
ImportError: /nix/store/m2by7m8lhdqr4q74d53jk5kp2m9rkhva-gcc-10.3.0-lib/lib/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /nix/store/lzyg8z14lvg46ic70ncxbmwjrdc9xyq0-boost-1.77.0/lib/libboost_unit_test_framework.so.1.77.0)
>>> 

Hi, thanks for the reply! I’ve managed to make it work here. Regarding the problem you had, I did not manage to replicate it… I just had some errors regarding some missing python dependencies. I fixed them by adding the libs resulting on the following nix files:
./librelora/default.nix

{ lib
, stdenv
, fetchFromGitLab
, cmake
, pkg-config
, cppunit
, boost
, log4cpp
, python
, doxygen
, gnuradio
, mpir
, volk
, gmp
, liquid-dsp
, icu
, spdlog
, git
, thrift
}:

stdenv.mkDerivation {
  pname = "gr-librelora";
  version = "1.3";
  src = fetchFromGitLab {
    owner = "jpsimas";
    repo = "librelora";
    rev = "v1.3";
    sha256 = "1g0sgasjngzwd9pgbb3bnswy6c0k29j0rld0k862w2zjsg52rwra";
  };

  nativeBuildInputs = [
    cmake
    pkg-config
    doxygen
    thrift
    python.pkgs.pybind11
    # python.pkgs.pygccxml
    # python.pkgs.thrift
  ] ++ gnuradio.pythonPkgs;

  buildInputs = [
    cppunit
    log4cpp
    boost
    gnuradio
    mpir
    volk
    gmp
    liquid-dsp
    icu
    spdlog
    git
  ];

  propagatedBuildInputs  = [
    gnuradio.python.pkgs.numpy
    gnuradio.python.pkgs.matplotlib # added
    gnuradio.python.pkgs.pyqt5 # added
  ];

  meta = with lib; {
    description = "GNURadio Based LoRa PHY receiver and transmitter implementations";
    homepage = "https://gitlab.com/jpsimas/librelora";
    license = licenses.gpl3Plus;
    platforms = platforms.linux ++ platforms.darwin;
    maintainers = with maintainers; [];
  };
}

./default.nix

{ pkgs ? import <nixpkgs> { }
}:

with pkgs;
with pkgs.lib;
let
  packages = rec {
    librelora = gnuradio.pkgs.callPackage ./librelora {
      inherit gnuradio;
      inherit (gnuradio) python boost;
      stdenv = gcc10Stdenv; # It's not compiling with last gcc version
    };

    shell = mkShell {
      name = "manolo";
      buildInputs = [
        librelora
        gnuradio.python
        gnuradio # added
      ];
    };
  };
in
packages

importing LibreLoRa inside python in:

nix-shell default.nix -A shell

I got:

[nix-shell:~/nix/forum]$ python
Python 3.9.12 (main, Mar 23 2022, 21:36:19) 
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import LibreLoRa
>>> 

So, I’m not sure what caused the problem you had, but I’ve noticed based off the version of boost in your system that you’re using the unstable Nix channel while I’m using 21.11, so there’s possibly some difference between the two causing the problem. Is it possible that by selecting gcc 10 you ended up with a nix-shell environment with an older version of libstdcxx then the one used to compile boost 1.77? Maybe making librelora to use boost 1.75 by replacing boost with boost175 (or gnuradio.boost) in it’s buildInputs solves the problem?