question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue
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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
bj0commented, Dec 22, 2021

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

1reaction
bj0commented, Oct 1, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Errno 13] Permission denied: '/usr/local/share/jupyter' #68
When I run python -m matlab_kernel install I get this error [Errno 13] Permission denied: '/usr/local/share/jupyter' . However my jupyter is located at ......
Read more >
python - Jupyter notebook permission error - Stack Overflow
The permission error may be due to directory is not in 777 mode. Please follow below command, it works for me: sudo chmod...
Read more >
sudo: jupyter: command not found & OSError: [Errno 13 ...
If I try to check if jupyter is in my path or not using, I get something in return. So how can I...
Read more >
500 error on loading notebook - Jupyter Community Forum
PermissionError : [Errno 13] Permission denied: '/usr/local/share/jupyter/nbconvert/templates/conf.json'. I do see in google discussions on ...
Read more >
Python PermissionError: [errno 13] permission denied Solution
The PermissionError: [errno 13] permission denied error occurs when you try to access a file from Python without having the necessary ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found