DavHau / mach-nix

Create highly reproducible python environments
MIT License
862 stars 106 forks source link

Unable to Build petsc and petsc4py #226

Closed rowhit closed 3 years ago

rowhit commented 3 years ago

I am trying to install mpi4py, petsc4py and petsc using the following shell.nix file:

{ 
  sources ?  import ./nix/sources.nix
, pkgs ?  import sources.nixpkgs { config= { allowUnfree = true; }; }
}:

let
  mach-nix = import (builtins.fetchGit {
    url = "https://github.com/DavHau/mach-nix/";
    # ref = "refs/tags/3.0.2";
    ref = "refs/tags/3.1.1";
    # ref = "refs/heads/conda";
    # ref = "refs/heads/conda-beta";
  }) { pkgs = pkgs; python = "python37"; };

  pythonPkgsWithMach = mach-nix.mkPython rec {
    requirements =  '' 
      # distutils_extra
      # pyqt5
      # ipython
      # numpy
      # matplotlib
      # openmdao[all]
      mpi4py
      petsc4py
      petsc
    '';

    providers = {
      # pyqt5 = "nixpkgs";
      # petsc = "nixpkgs";
    };
  };

in

pkgs.mkShell rec {
  name = "153599a1-openmdao-docs-walkthru";
  buildInputs = [ 

    pkgs.which
    pkgs.openssl
    pkgs.gcc
    pkgs.qt5.full
    pkgs.pkgconf
    pkgs.vscode-with-extensions
    pkgs.petsc
    pkgs.openmpi

    pkgs.poetry
    pkgs.python37Packages.virtualenv
    pkgs.python37Packages.pip
    pkgs.python37Packages.setuptools
    pkgs.python37Packages.venvShellHook

    pythonPkgsWithMach

  ];

  venvDir = ".venv";

  shellHook = ''
    export ENVNAME="${name}"
    virtualenv --no-setuptools ${venvDir}
    export PATH=$PWD/${venvDir}/bin:$PATH
    export PYTHONPATH=${venvDir}/lib/python3.7/site-packages/:$PYTHONPATH
    export LD_LIBRARY_PATH=${pkgs.libngspice}/lib:${pkgs.stdenv.cc.cc}/lib:$LD_LIBRARY_PATH
  '';

  postShellHook = ''
    ln -sf PYTHONPATH/* ${venvDir}/lib/python3.7/site-packages
    # manually install python packages using pip
    # pip install -e . # dev mode
    # pip install --no-deps git+https://gitlab.com/petsc/petsc
    # pip install --no-deps git+https://gitlab.com/petsc/petsc4py
  '';
}

However the above script fails and I get the following error. I have seen it with both conda ref as well the default.

building '/nix/store/nnvr7v6v7fhhrg4p1ar9r88hmm3q1q44-python3.7-petsc-3.14.1.drv'...
Sourcing python-recompile-bytecode-hook.sh
Sourcing python-remove-tests-dir-hook
Sourcing python-catch-conflicts-hook.sh
Sourcing python-remove-bin-bytecode-hook.sh
Sourcing setuptools-build-hook
Using setuptoolsBuildPhase
Using setuptoolsShellHook
Sourcing pip-install-hook
Using pipInstallPhase
Sourcing python-imports-check-hook.sh
Using pythonImportsCheckPhase
Sourcing python-namespaces-hook
unpacking sources
unpacking source archive /nix/store/1rbgc51wv2mxrq7mv12hdakgzwlbflf8-petsc-3.14.1.tar.gz
source root is petsc-3.14.1
setting SOURCE_DATE_EPOCH to timestamp 1604427435 of file petsc-3.14.1/TAGS
patching sources
configuring
configure flags: --prefix=/nix/store/rlzp5bsx97nbd06kn7d35smhg2vl9x18-python3.7-petsc-3.14.1
Error! Could not locate Python (with distutils.sysconfig)! Please install and have python3, python, or python2 (with distutils.sysconfig) in PATH.
Or use: /path/to/valid/python configure --prefix=/nix/store/rlzp5bsx97nbd06kn7d35smhg2vl9x18-python3.7-petsc-3.14.1
builder for '/nix/store/nnvr7v6v7fhhrg4p1ar9r88hmm3q1q44-python3.7-petsc-3.14.1.drv' failed with exit code 127
cannot build derivation '/nix/store/pq9vmr4ajrv9bdrcklifcywl63zv547l-python3-3.7.9-env.drv': 1 dependencies couldn't be built
error: build of '/nix/store/pq9vmr4ajrv9bdrcklifcywl63zv547l-python3-3.7.9-env.drv' failed
DavHau commented 3 years ago

Error! Could not locate Python (with distutils.sysconfig)! Please install and have python3, python, or python2

petsc seems unable to detect python3 during installation. I recommend you have a look into what the installer does exactly. You also might want to open an upstream issue and ask the maintainer to release wheels on pypi.