Issue with `django_1_11`: No module named 'django'

#1

I’m trying to bring Mathics back to life. So I created the following package:

{ lib, pkgs, fetchFromGitHub
, python3Packages
}:

python3Packages.buildPythonApplication rec {
  name = "mathics-${version}";
  version = "1.0";

  src = fetchFromGitHub {
    owner = "suhr";
    repo = "Mathics";
    rev = "61d603bce91c8c55d70b8b5b76cfcea2a2d8693a";
    sha256 = "0d7l1k3va2axg4hl0ckvjfz4sgdgw7brnlhfybgv99shzm25irp4";
  };

  propagatedBuildInputs = with python3Packages; [
    sympy numpy pexpect django_1_11 mpmath dateutil colorama six
  ];

  doCheck = true;

  meta = {
    broken = true;

    description = "A free, light-weight alternative to Mathematica";
    homepage = https://mathics.github.io/;
    license = lib.licenses.gpl3;
    maintainers = [ ];
  };
}

But then I get this issue:

% ./result/bin/mathicsserver                                                                                                                                                                                 ~/Projects/nur-packages
warning: database file /home/suhr/.local/var/mathics/mathics.sqlite not found

Creating database /home/suhr/.local/var/mathics/mathics.sqlite
Traceback (most recent call last):
  File "/nix/store/57s7dcw2rkggaiq4dmi5kqs5gr0166b3-mathics-1.0/lib/python3.7/site-packages/mathics/manage.py", line 13, in <module>
    from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
error: failed to create database

Now do I fix the package so mathics could import django?

#2

Just to save other people some time. This needs to built against nixpkgs b2481d683069c218888eaa77aa56a8afacd42d19 (current master).
The problem I found is probably:

[pid  1968] execve("/nix/store/zracigqmjvybwpyvpk4g52iajs6ksp31-python3-3.7.3/bin/python3.7", ["/nix/store/zracigqmjvybwpyvpk4g52iajs6ksp31-python3-3.7.3/bin/python3.7", "/nix/store/61lvgr4imlg0db1ig2r7wr14rx0v9vmc-mathics-1.0/lib/python3.7/site-packages/mathics/manage.py", "migrate", "--noinput"], 0x1666520 /* 81 vars */) = 0

It calls python again, but doesn’t pass on the site dirs (the python executable is not wrapped), so django can’t be found from the new process. I don’t know enough about Python to fix this, but maybe someone does :slight_smile:

#3

I got it to build, though I’m sure I’m missing something obvious.
Try this:

{ lib, pkgs, fetchFromGitHub
, python3Packages, python3, makeWrapper
}:

let
  deps = with python3Packages; [
    sympy numpy pexpect django_1_11 mpmath dateutil colorama six
  ];
  pythonEnv = python3.withPackages (p: deps);
in python3Packages.buildPythonApplication rec {
  name = "mathics-${version}";
  version = "1.0";

  src = fetchFromGitHub {
    owner = "suhr";
    repo = "Mathics";
    rev = "61d603bce91c8c55d70b8b5b76cfcea2a2d8693a";
    sha256 = "0d7l1k3va2axg4hl0ckvjfz4sgdgw7brnlhfybgv99shzm25irp4";
  };

  propagatedBuildInputs = deps;

  postPatch = ''
    substituteInPlace mathics/server.py \
      --replace "sys.executable, " ""
  '';

  postInstall = ''
    for manage in $(find $out -name manage.py); do
      chmod +x $manage
      wrapProgram $manage --set PYTHONPATH "$PYTHONPATH:${pythonEnv}/${pythonEnv.sitePackages}"
    done
  '';

  doCheck = false;

  meta = {
    description = "A free, light-weight alternative to Mathematica";
    homepage = https://mathics.github.io/;
    license = lib.licenses.gpl3;
    maintainers = [ ];
  };
}
1 Like