Jupyter notebook with batteries


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


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)


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.


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


Have you looked yet in the manual?


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


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


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.


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