coconut: PermissionError: [Errno 13] Permission denied: '/usr/share/jupyter'

gurkenglas@Gurkenglas-PC:~/.local/lib/python3.9/site-packages/lenses$ coconut --ipython notebook
Traceback (most recent call last):
  File "/home/gurkenglas/.local/lib/python3.9/site-packages/coconut/command/command.py", line 293, in handling_exceptions
    yield
  File "/home/gurkenglas/.local/lib/python3.9/site-packages/coconut/command/command.py", line 129, in cmd
    self.use_args(parsed_args, interact, original_args=args)
  File "/home/gurkenglas/.local/lib/python3.9/site-packages/coconut/command/command.py", line 255, in use_args
    self.start_jupyter(args.jupyter)
  File "/home/gurkenglas/.local/lib/python3.9/site-packages/coconut/command/command.py", line 719, in start_jupyter
    custom_kernel_dir = install_custom_kernel()
  File "/home/gurkenglas/.local/lib/python3.9/site-packages/coconut/kernel_installer.py", line 64, in install_custom_kernel
    os.makedirs(kernel_dest)
  File "/usr/lib/python3.9/os.py", line 215, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/usr/lib/python3.9/os.py", line 215, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/usr/lib/python3.9/os.py", line 225, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/usr/share/jupyter'
(you should report this at https://github.com/evhub/coconut/issues/new)
Exiting due to PermissionError.
gurkenglas@Gurkenglas-PC:~/.local/lib/python3.9/site-packages/lenses$ coconut -v
Coconut: Version 1.5.0 [Fish License] running on Python 3.9.5 and Cython
cPyparsing v2.4.5.0.1.2

got coconut via python3.9 -m pip install coconut.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (8 by maintainers)

Commits related to this issue

Most upvoted comments

I would just like to put in a quick update for anyone who finds this and tries to use nix with coconut. I was able to significantly simplify it.

I put it up in a repo at https://github.com/bj0/nix-coconut

If you have nix with flakes support, you can run it directly from there with nix run github:bj0/nix-coconut

Ok I learned enough to get it to work. For anyone else who’s interested here’s whats what:

I used jupyterWith to create the jupyter environment, but I had to add a custom kernel for coconut. I based it off one of their pre-existing ones, it was pretty straightforward.

I also had to use mach-nix to pull an updated coconut, since the one in nixpkgs is 1.4.3, and I wasn’t sure of all the dependencies for building from scratch.

The files are below, a shell.nix file to launch with nix-shell, and a coconut/default.nix file that has the kernel definition. I couldn’t find a coconut icon on the doc site so i just copied a random icon from jupyterWith (it’s used when you launch jupyter lab).

shell.nix

{ pkgs ? import (fetchTarball https://github.com/nixos/nixpkgs/archive/nixpkgs-unstable.tar.gz) {} }:

let
    mach-nix = import (builtins.fetchGit {
        url = "https://github.com/DavHau/mach-nix";
        ref = "refs/tags/3.3.0";
      }) {
        # python = "python38";
        pypiDataRev = "e747f31df341f0b8fe9bef114043bdc51acbbcaf";
        pypiDataSha256 = "0knpr745w8xklklbb915z1084xymy0w1vi9hz9ss56hii70v4wrg";
    };

    jupyter = import (builtins.fetchGit {
        url = https://github.com/tweag/jupyterWith;
    }) {};

    # make a python with updated coconut
    mnPython = mach-nix.mkPython {
        requirements = ''
            coconut>=1.5.0
        '';
        ignoreCollisions = true;
    };

    # create kernel
    icoconut = pkgs.callPackage ./coconut {
        name = "coconut";
        python3 = mnPython.python;
    };

    # create jupyter environemnt
    jupyterEnvironment = jupyter.jupyterlabWith {
        kernels = [ icoconut ];
        # add console
        extraPackages = p: [ p.python3Packages.jupyter_console ];
    };

in
    jupyterEnvironment.env.overrideAttrs (oldAttrs: {
        shellHook = oldAttrs.shellHook + ''
            jupyter console --kernel coconut_coconut
        '';
    })

coconut/default.nix

{ stdenv
, python3
, name ? "nixpkgs"
, packages ? p: []
, pkgs
, pkg ? "coconut"
}:

let
  kernelEnv = python3.withPackages ( p: [ p."${pkg}" ]);

  kernelFile = {
    argv = [
      "${kernelEnv.interpreter}"
      "-m"
      "coconut.icoconut"
      "-f"
      "{connection_file}"
    ];
    display_name = "Coconut " + name;
    language = "coconut";
    logo64 = "logo-64x64.svg";
  };

  icoconut = stdenv.mkDerivation {
    name = "icoconut-kernel";
    phases = "installPhase";
    src = ./coconut.png;
    buildInputs = [];
    installPhase = ''
      mkdir -p $out/kernels/coconut_${name}
      cp $src $out/kernels/coconut_${name}/logo-64x64.png
      echo '${builtins.toJSON kernelFile}' > $out/kernels/coconut_${name}/kernel.json
    '';
  };
in
  {
    spec = icoconut;
    runtimePackages = packages pkgs;
  }

This works great, launching a coconut+jupyter console. One thing to note is that the way jupyterWith works, there is a separate “shell” environment that is different than the kernel environments, which means coconut is not available in the shell. This means you can’t coconut --jupyter console, so you must jupyter console --kernel coconut_<name>.

I was able to fix this by using jupyterWith’s overlay feature, and with 1.5.0dev82, It worked with warings:

PermissionError: [Errno 13] Permission denied: 'kernel.json'
CoconutWarning: Coconut Jupyter kernel installation failed due to above error (try again with 'sudo').
CoconutWarning: failed to install 'coconut' Jupyter kernel (falling back to 'coconut_pyX' kernels instead)
Coconut: Installing Jupyter kernels 'coconut_py', 'coconut_py2', 'coconut_py3'...
CoconutWarning: could not find 'coconut' kernel; using 'coconut_py3' kernel instead
Coconut: Successfully installed Jupyter kernels: 'coconut_py', 'coconut_py2', 'coconut_py3'
Jupyter console 6.4.0

Coconut 1.5.0-post_dev82 [Fish License]

Unfortunately, it also created kernel files in ~/.local/share/jupyter/kernels, which I didn’t want it to do, so for now I’ll just use what I have above.

PS: it’s easy to use the development version with the following changes:

    ...

    # make a python with updated coconut
    mnPython = mach-nix.mkPython {
        requirements = ''
            coconut-develop>=1.5.0dev82
        '';
        ignoreCollisions = true;
    };

    ...

    # create kernel
    icoconut = pkgs.callPackage ./coconut {
        name = "coconut";
        python3 = mnPython.python;
        pkg = "coconut-develop";
    };

Note that mach-nix works off a snapshot of pypi that’s fixed with a revision and hash, so if you want to use a newer dev build than what’s in the snapshot you have to get a new revision/hash from https://github.com/DavHau/pypi-deps-db. Or you can just figure out how to build it from source.