如何在JupyterLab中列出所有现有工作区?

问题描述 投票:4回答:3

如何在JupyterLab中列出所有现有工作区?

我知道可以在URL中查看当前工作区名称:

enter image description here

enter image description here

jupyter-notebook jupyter jupyter-lab
3个回答
5
投票

创建工作区时,这将在~/.jupyter/lab/workspaces中创建一个文件。工作区的名称位于相应JSON文件的['metadata']['id']项中。

因此,列出所有工作区的简单代码是:

import os, glob, json
for fname in glob.glob(os.path.join(os.environ['HOME'], ".jupyter/lab/workspaces/*")):
     with open (fname, "r") as read_file:
         print (json.load(read_file)['metadata']['id'])

为方便起见,我用这段代码创建了一个gist。我还添加了一些化妆品来直接生成不同的URL:

$ list_workspaces.py -u
http://10.164.5.234:8888/lab
http://10.164.5.234:8888/lab/workspaces/BBCP
http://10.164.5.234:8888/lab/workspaces/blog

3
投票

正如其他人所指出的那样,工作区文件位于~/.jupyter/lab/workspaces。每个工作区都由.jupyterlab-workspace表示,它实际上只是一个JSON文件。

如果安装了CLI工具jq,则以下单行程序会为您提供工作区的快速列表:

cat ~/.jupyter/lab/workspaces/* | jq -r '.metadata.id'

样本输出:

/lab
/lab/workspaces/aaaaaaaaaaaa
/lab/workspaces/xxxxxxxxxx

1
投票

我想你可以试试

ls ~/.jupyter/lab/workspaces

每次创建新工作区时,都会生成相应的文件。更详细的文档是here

© www.soinside.com 2019 - 2024. All rights reserved.