Problem installing Scipy with Poetry install a nix shell

Hello,

I’m trying to install scipy with Poetry inside a nix shell.
Here is my nix.shell

{ pkgs ? import <nixpkgs> {} }:


pkgs.mkShell {
  nativeBuildInputs = [
    pkgs.lapack-reference
    pkgs.python310
    (pkgs.poetry.override { python = pkgs.python310; })
  ];
}

When I run poetry add scikit-image (which has to install scipy) I get this error:
numpy.distutils.system_info.NotFoundError: No BLAS/LAPACK libraries found.

I tried to specify other BLAS provider (instead of lapack-reference) like openblas but it doesn’t work.

I’m relatively new to Nix and Nix/OS, could you help me?

Thanks

How to solve this depends on the discovery mechanism that scikit is using.

If you are lucky, adding pkgConfig to native and the libs to regular build inputs is sufficient, if you are unlucky though, you will need to build env vars pointing to headers and/or libs on your own.

Thank you.
I will give it a try.

Or if it makes your life more simple, you can try: https://python.on-nix.com/projects/scipy-latest-python39/

I almost made it work with this nix.shell

{ pkgs ? import <nixpkgs> {} }:


pkgs.mkShell {
  nativeBuildInputs = [
    pkgs.lapack-reference
    pkgs.python310
    pkgs.zlib
    (pkgs.poetry.override { python = pkgs.python310; })
  ];

  shellHook = ''
    export BLAS="${pkgs.lapack-reference}/lib/libblas.so"
    export LAPACK="${pkgs.lapack-reference}/lib/liblapack.so"
    export LD_LIBRARY_PATH="${pkgs.zlib}/lib"
  '';

}

But now I get another error, later, with a lot of compiler outputs:

    ...
    ...
    INFO: CCompilerOpt.__init__[1734] : initialize targets groups
    INFO: CCompilerOpt.__init__[1736] : parse target group simd_test
    INFO: CCompilerOpt._parse_target_tokens[1947] : skip targets (ASIMD XOP VSX2 FMA4 NEON VSX VSX3) not part of baseline or dispatch-able features
    INFO: CCompilerOpt._parse_policy_not_keepbase[2059] : skip baseline features (SSE2)
    INFO: CCompilerOpt.generate_dispatch_header[2280] : generate CPU dispatch header: (build/src.linux-x86_64-3.10/numpy/distutils/include/npy_cpu_dispatch_config.h)
    WARN: CCompilerOpt.generate_dispatch_header[2289] : dispatch header dir build/src.linux-x86_64-3.10/numpy/distutils/include does not exist, creating it
    INFO: CCompilerOpt.feature_extra_checks[1554] : Testing extra checks for feature 'AVX512F' (AVX512F_REDUCE)
    INFO: C compiler: gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC
    
    INFO: compile options: '-c'
    extra options: '-msse -msse2 -msse3 -mssse3 -msse4.1 -mpopcnt -msse4.2 -mavx -mf16c -mfma -mavx2 -mavx512f -Werror'
    INFO: CCompilerOpt.feature_extra_checks[1554] : Testing extra checks for feature 'AVX512_SKX' (AVX512BW_MASK AVX512DQ_MASK)
    INFO: C compiler: gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC
    
    INFO: compile options: '-c'
    extra options: '-msse -msse2 -msse3 -mssse3 -msse4.1 -mpopcnt -msse4.2 -mavx -mf16c -mfma -mavx2 -mavx512f -mavx512cd -mavx512vl -mavx512bw -mavx512dq -Werror'
    INFO: C compiler: gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC
    
    INFO: compile options: '-c'
    extra options: '-msse -msse2 -msse3 -mssse3 -msse4.1 -mpopcnt -msse4.2 -mavx -mf16c -mfma -mavx2 -mavx512f -mavx512cd -mavx512vl -mavx512bw -mavx512dq -Werror'
    INFO: building 'mach' library
    error: library mach has Fortran sources but no Fortran compiler found
    INFO:
    ########### CLIB COMPILER OPTIMIZATION ###########
    INFO: Platform      :
      Architecture: x64
      Compiler    : gcc
    
    CPU baseline  :
      Requested   : 'min'
      Enabled     : SSE SSE2 SSE3
      Flags       : -msse -msse2 -msse3
      Extra checks: none
    
    CPU dispatch  :
      Requested   : 'max -xop -fma4'
      Enabled     : SSSE3 SSE41 POPCNT SSE42 AVX F16C FMA3 AVX2 AVX512F AVX512CD AVX512_KNL AVX512_KNM AVX512_SKX AVX512_CLX AVX512_CNL AVX512_ICL
      Generated   : none
    INFO: CCompilerOpt.cache_flush[817] : write cache to path -> /run/user/1000/pip-req-build-lmxxwzag/build/temp.linux-x86_64-3.10/ccompiler_opt_cache_clib.py
    ----------------------------------------
    ERROR: Failed building wheel for scipy
  Failed to build scipy
  ERROR: Could not build wheels for scipy, which is required to install pyproject.toml-based projects

Thanks, but I would prefer to use python 3.10 for this project.

Chiming in a bit late, here. But, it looks like you were just missing the fortran compiler. The following worked for me.

{ pkgs ? import <nixpkgs> {} }:


pkgs.mkShell {
  nativeBuildInputs = [
    pkgs.gfortran
    pkgs.pkg-config
    pkgs.lapack-reference
    pkgs.python310
    (pkgs.poetry.override { python = pkgs.python310; })
  ];
  shellHook = ''
    export BLAS="${pkgs.lapack-reference}/lib/libblas.so"
    export LAPACK="${pkgs.lapack-reference}/lib/liblapack.so"
    export LD_LIBRARY_PATH="${pkgs.zlib}/lib"
  '';
}