5

我已经构建了一个包含最新 anaconda 版本的奇点映像(jupyter.sif),我想用它来运行一个 jupyter 笔记本。

我想运行这样的东西:

singularity exec \
  --bind /path/outside/image/:/path/inside/image/ \
  jupyter.sif jupyter notebook \
    --notebook-dir=/path/to/dir --no-browser --ip=127.0.0.1

本质上,只需启动一个普通的 jupyter notebook,它将使用 python 版本和安装在奇异图像中的包。理想情况下,笔记本将在图像之外读取和写入文件(因此我指定了绑定路径)。

但是,当我运行上述命令时,出现以下错误:

> Traceback (most recent call last):   File
> "/opt/conda/lib/python3.7/site-packages/traitlets/traitlets.py", line
> 528, in get
>     value = obj._trait_values[self.name] KeyError: 'runtime_dir'
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):
> 
>   File "/opt/conda/bin/jupyter-notebook", line 11, in <module>
>     sys.exit(main())
> 
>   File
> "/opt/conda/lib/python3.7/site-packages/jupyter_core/application.py",
> line 266, in launch_instance
>     return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
> 
>   File
> "/opt/conda/lib/python3.7/site-packages/traitlets/config/application.py",
> line 657, in launch_instance
>     app.initialize(argv)
> 
>   File "<decorator-gen-7>", line 2, in initialize
> 
>   File
> "/opt/conda/lib/python3.7/site-packages/traitlets/config/application.py",
> line 87, in catch_config_error
>     return method(app, *args, **kwargs)
> 
>   File
> "/opt/conda/lib/python3.7/site-packages/notebook/notebookapp.py", line
> 1626, in initialize
>     self.init_configurables()
> 
>   File
> "/opt/conda/lib/python3.7/site-packages/notebook/notebookapp.py", line
> 1319, in init_configurables
>     connection_dir=self.runtime_dir,
> 
>   File
> "/opt/conda/lib/python3.7/site-packages/traitlets/traitlets.py", line
> 556, in __get__
>     return self.get(obj, cls)
> 
>   File
> "/opt/conda/lib/python3.7/site-packages/traitlets/traitlets.py", line
> 535, in get
>     value = self._validate(obj, dynamic_default())
> 
>   File
> "/opt/conda/lib/python3.7/site-packages/jupyter_core/application.py",
> line 99, in _runtime_dir_default
>     ensure_dir_exists(rd, mode=0o700)
> 
>   File
> "/opt/conda/lib/python3.7/site-packages/jupyter_core/utils/__init__.py",
> line 13, in ensure_dir_exists
>     os.makedirs(path, mode=mode)
> 
>   File "/opt/conda/lib/python3.7/os.py", line 211, in makedirs
>     makedirs(head, exist_ok=exist_ok)
> 
>   File "/opt/conda/lib/python3.7/os.py", line 211, in makedirs
>     makedirs(head, exist_ok=exist_ok)
> 
>   File "/opt/conda/lib/python3.7/os.py", line 221, in makedirs
>     mkdir(name, mode)
> 
> OSError: [Errno 30] Read-only file system: '/run/user'

我认为这是因为笔记本正在尝试在图像中写入内容,并且因为我没有将图像作为 sudo 运行(我不想这样做),而且我在执行图像时也没有指定 --writable (也不想这样做),它抱怨无法在图像中写入。

有没有办法“告诉”图像在我的主目录而不是图像内部读取和写入文件?

谢谢

4

3 回答 3

4

我刚刚遇到了同样的问题,这似乎已经为我解决了:将 /run/user 内部映射到容器到外部的工作目录(或您选择的目录)。对于您的情况,可能意味着:

singularity exec --bind /path/outside/image/:/path/inside/image/ --bind $PWD:/run/user jupyter.sif jupyter notebook --notebook-dir=/path/to/dir --no-browser --ip=127.0.0.1

像这样运行时,在我的情况下1000创建了一个文件夹

于 2019-02-16T15:35:56.310 回答
0

这适用于奇点实例,例如:

   singularity instance.start --writable --contain --bind shared:/shared sandbox/ jupyter
于 2019-06-10T09:38:09.430 回答
0

接受的答案有效,但这是另一个不需要绑定安装的解决方案。可以unset XDG_RUNTIME_DIR在运行 jupyter notebook 之前运行,这个错误就会消失。

于 2021-07-30T18:48:00.660 回答