From 10a9082637d0e130f91db851b065bf24f124c7ad Mon Sep 17 00:00:00 2001 From: Alexander Artemenko Date: Fri, 13 Nov 2020 11:29:45 +0300 Subject: [PATCH] Allow use ~/ in the kernel's command or it's arguments. After this patch you'll be able to do this in a kernel spec: { "argv": ["~/the-project/jupyter/kernel/run", "-f", "{connection_file}"], "display_name": "The Project (dev)", "language": "python" } This can be useful when you are installing kernel with --user option into /home/my-name/.local/share/jupyter/kernels/ and having your jupyter notebooks in different subdirectories of ~/the-project/ folder. In this case kernel for each notebook is started in the notebook's subdirectory and without ~/ in the spec Jupyter is unable to find a file for running custom kernel. --- jupyter_client/launcher.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/jupyter_client/launcher.py b/jupyter_client/launcher.py index 3dcaec4d6..0da669a19 100644 --- a/jupyter_client/launcher.py +++ b/jupyter_client/launcher.py @@ -128,6 +128,9 @@ def launch_kernel(cmd, stdin=None, stdout=None, stderr=None, env=None, env['JPY_PARENT_PID'] = str(os.getpid()) try: + # Allow to use ~/ in the command or its arguments + cmd = list(map(os.path.expanduser, cmd)) + proc = Popen(cmd, **kwargs) except Exception as exc: msg = (