Jupyter notebook with batteries


#1

How do I get a Python notebook with numpy, scipy, matplotlib and other essential libraries?


#2

You can run:
nix-shell -p pythonPackages.numpy pythonPackages.notebook then jupyter notebook from within the shell and add all other libraries you need if available. (use nix search to check availability)


#3

It’s in the Nixpkgs manual: python3.withPackages(ps: with ps; [ numpy scipy matplotlib ])

Avoid using nix-shell -p pythonPackages.numpy pythonPackages.notebook. It “works” because it uses a setup hook for setting up PYTHONPATH, but it is not guaranteed to work. Also, not all packages will propagate the interpreter.


#4

Is there a less ad-hoc way than nix-shell? Like installing a derivation with the required environment.


#5

Have you looked yet in the manual?


#6

Yes, I did. Should I read it once again?


#7

Maybe you want to create an overlay with the following contents:

self: super: {
   jupyterWithBatteries = super.jupyter.override {
      python3 = super.python3.withPackages(ps: with ps; [ numpy scipy matplotlib ]);
   };
} 

then run

nix-env -iA nixpkgs.jupyterWithBatteries

to install the modified jupyter


#8

I added the following into $HOME/.config/nixpkgs/config.nix:

  packageOverrides = pkgs: with pkgs; {
    jupyterWithBatteries = pkgs.jupyter.override {
      python3 = pkgs.python3.withPackages(ps: with ps; [
        numpy scipy matplotlib
      ]);
    };
  };

nix-env -iA nixos.jupyterWithBatteries installs jupyter but numpy and other libraries are not available in notebooks.


#9

Oh sorry, my fault :frowning: reviewed the source, you should override the definitions attribute, which looks like this: https://github.com/NixOS/nixpkgs/blob/beaf69cee298e092698dd2da2e4758b7811859ad/pkgs/applications/editors/jupyter/kernel.nix#L5