# Slicer Jupyter docker with CUDA

**URL:** https://discourse.slicer.org/t/slicer-jupyter-docker-with-cuda/23519
**Category:** Support
**Created:** [May 21, 2022, 6:08pm UTC](https://discourse.slicer.org/t/slicer-jupyter-docker-with-cuda/23519 "2022-05-21T18:08:07Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Jakub\_Mitura](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jakub_mitura/32/8858_2.png) [@Jakub\_Mitura](https://discourse.slicer.org/u/Jakub_Mitura)
#### Post date: [May 21, 2022, 6:08pm UTC](https://discourse.slicer.org/t/slicer-jupyter-docker-with-cuda/23519/1 "2022-05-21T18:08:07Z")

</div>

Hello I try to customize official slicer docker for jupyter, and integrate it with vs code development in a container.

I managed already to Install and test CUDA - which seem to works ok (pytorch detects it)

Now I have some problems, first I want to ask is it possible to use slicer extensions from the jupyter - primarly but not exclusively I am interested in installing SlicerRadiomics extension and use it from jupyter.

Secondly I try to install extension by modyfing install.sh  
and adding after SlicerJupyter is installed

```auto

echo "Install extensions"
$slicer_executable -c '
em = slicer.app.extensionsManagerModel()
extensionMetaData = em.retrieveExtensionMetadataByName("SlicerRadiomics")
if slicer.app.majorVersion*100+slicer.app.minorVersion < 413:
    # Slicer-4.11
    itemId = extensionMetaData["item_id"]
    url = f"{em.serverUrl().toString()}/download?items={itemId}"
    extensionPackageFilename = f"{slicer.app.temporaryPath}/{itemId}"
    slicer.util.downloadFile(url, extensionPackageFilename)
else:
    # Slicer-4.13
    itemId = extensionMetaData["_id"]
    url = f"{em.serverUrl().toString()}/api/v1/item/{itemId}/download"
    extensionPackageFilename = f"{slicer.app.temporaryPath}/{itemId}"
    slicer.util.downloadFile(url, extensionPackageFilename)
    # Prevent showing popups for installing dependencies
    # (this is not needed right now for SlicerJupyter, but we still add this line here
    # because this docker image may be used by other projects as a starting point)
    em.interactive = False
em.installExtension(extensionPackageFilename)
'

```

Yet It gives error

```auto
[2022-05-21T18:07:13.536Z] Install extensions
[2022-05-21T18:07:15.830Z] Traceback (most recent call last):
[2022-05-21T18:07:15.830Z] File "<string>", line 12, in <module>
[2022-05-21T18:07:15.831Z] KeyError: '_id'
[2022-05-21T18:07:16.363Z] The command '/bin/sh -c ./install.sh ${HOME}/Slicer/Slicer && rm ${HOME}/install.sh' returned a non-zero code: 1
[2022-05-21T18:07:16.366Z] Stop (15155 ms): Run: docker build -f /home/jakub/projects/slicerModifB/.devcontainer/Dockerfile -t vsc-slicermodifb-cec2d2e6cdb09b3c149f8f6bee02d187 /home/jakub/projects/slicerModifB/.devcontainer
[2022-05-21T18:07:16.367Z] Error: Command failed: docker build -f /home/jakub/projects/slicerModifB/.devcontainer/Dockerfile -t vsc-slicermodifb-cec2d2e6cdb09b3c149f8f6bee02d187 /home/jakub/projects/slicerModifB/.devcontainer
[2022-05-21T18:07:16.367Z] at Tu (/home/jakub/.vscode/extensions/ms-vscode-remote.remote-containers-0.234.0/dist/spec-node/devContainersSpecCLI.js:221:3219)
[2022-05-21T18:07:16.367Z] at processTicksAndRejections (node:internal/process/task_queues:96:5)
[2022-05-21T18:07:16.367Z] at async LR (/home/jakub/.vscode/extensions/ms-vscode-remote.remote-containers-0.234.0/dist/spec-node/devContainersSpecCLI.js:221:1567)
[2022-05-21T18:07:16.367Z] at async zy (/home/jakub/.vscode/extensions/ms-vscode-remote.remote-containers-0.234.0/dist/spec-node/devContainersSpecCLI.js:221:594)
[2022-05-21T18:07:16.367Z] at async $R (/home/jakub/.vscode/extensions/ms-vscode-remote.remote-containers-0.234.0/dist/spec-node/devContainersSpecCLI.js:226:2007)
[2022-05-21T18:07:16.367Z] at async Zy (/home/jakub/.vscode/extensions/ms-vscode-remote.remote-containers-0.234.0/dist/spec-node/devContainersSpecCLI.js:226:3112)
[2022-05-21T18:07:16.367Z] at async BR (/home/jakub/.vscode/extensions/ms-vscode-remote.remote-containers-0.234.0/dist/spec-node/devContainersSpecCLI.js:226:12448)
[2022-05-21T18:07:16.367Z] at async qR (/home/jakub/.vscode/extensions/ms-vscode-remote.remote-containers-0.234.0/dist/spec-node/devContainersSpecCLI.js:226:12204)
[2022-05-21T18:07:16.370Z] Stop (15293 ms): Run: /snap/code/97/usr/share/code/code /home/jakub/.vscode/extensions/ms-vscode-remote.remote-containers-0.234.0/dist/spec-node/devContainersSpecCLI.js up --user-data-folder /home/jakub/.config/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --container-data-folder .vscode-server/data/Machine --container-system-data-folder /var/vscode-server --workspace-folder /home/jakub/projects/slicerModifB --workspace-mount-consistency cached --id-label vsch.local.folder=/home/jakub/projects/slicerModifB --id-label vsch.quality=stable --log-level debug --log-format json --config /home/jakub/projects/slicerModifB/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[2022-05-21T18:07:16.370Z] Exit code 1
[2022-05-21T18:07:16.372Z] Command failed: /snap/code/97/usr/share/code/code /home/jakub/.vscode/extensions/ms-vscode-remote.remote-containers-0.234.0/dist/spec-node/devContainersSpecCLI.js up --user-data-folder /home/jakub/.config/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --container-data-folder .vscode-server/data/Machine --container-system-data-folder /var/vscode-server --workspace-folder /home/jakub/projects/slicerModifB --workspace-mount-consistency cached --id-label vsch.local.folder=/home/jakub/projects/slicerModifB --id-label vsch.quality=stable --log-level debug --log-format json --config /home/jakub/projects/slicerModifB/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[2022-05-21T18:07:16.373Z] Exit code 1

```

My docker project

> **[GitHub - jakubMitura14/slicerModifB](https://github.com/jakubMitura14/slicerModifB/tree/master)**
>
> master

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [May 22, 2022, 1:38pm UTC](https://discourse.slicer.org/t/slicer-jupyter-docker-with-cuda/23519/2 "2022-05-22T13:38:00Z")

</div>

This sounds great and it seems that you are making good progress.

> [@Jakub\_Mitura](#):
>
> is it possible to use slicer extensions from the jupyter - primarly but not exclusively I am interested in installing SlicerRadiomics extension and use it from jupyter

Yes, this should be no problem at all. You can install other extensions the same way as SlicerJupyter. You can use any modules in any extensions from Jupyter the same way as from the Python console or any Python module. You can find more information in the [Python FAQ](https://slicer.readthedocs.io/en/latest/developer_guide/python_faq.html).

> [@Jakub\_Mitura](#):
>
> I try to install extension by modyfing install.sh  
> and adding after SlicerJupyter is installed

If `_id` key is missing from the extension description then it means that the extension is not available for that Slicer version. I would recommend to use the latest Slicer Stable version now (Slicer 5.0.x). You can see the list of extensions available for this version here:

[https://extensions.slicer.org/catalog/All/30822/linux](https://extensions.slicer.org/catalog/All/30822/linux)

---

<div class="post-metadata">

### Author: ![Jakub\_Mitura](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jakub_mitura/32/8858_2.png) [@Jakub\_Mitura](https://discourse.slicer.org/u/Jakub_Mitura)
#### Post date: [May 22, 2022, 3:50pm UTC](https://discourse.slicer.org/t/slicer-jupyter-docker-with-cuda/23519/3 "2022-05-22T15:50:27Z")

</div>

Fantastic, yes now it works as I got newer version - when I open python console in the container .Hovewer How to get a token inside the container

as I need [http://127.0.0.1:8888/?token](http://127.0.0.1:8888/?token) to open jupyter notebook server connection - I know that I can do it by building in a normal way docker image from command line but from VS code inside the container it is less obvious for me 🙂

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [May 23, 2022, 3:20am UTC](https://discourse.slicer.org/t/slicer-jupyter-docker-with-cuda/23519/4 "2022-05-23T03:20:46Z")

</div>

You can print the token to the output and capture it from there; or write the token to a file in a mapped folder and read it from that file.

Alternatively, you can [specify a custom token for the Jupyter server](https://stackoverflow.com/questions/47492150/how-do-i-set-a-custom-token-for-a-jupyter-notebook), for example by passing it as a command-line argument to the docker container or via an environment variable.

---

<div class="post-metadata">

### Author: ![Jakub\_Mitura](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jakub_mitura/32/8858_2.png) [@Jakub\_Mitura](https://discourse.slicer.org/u/Jakub_Mitura)
#### Post date: [June 2, 2022, 9:10am UTC](https://discourse.slicer.org/t/slicer-jupyter-docker-with-cuda/23519/5 "2022-06-02T09:10:43Z")

</div>

ok It is working now thanks @lassoan !, If you consider it worth it You may use it as an example for others ([if yes here is the link to repository](https://github.com/jakubMitura14/SlicerNotebookCUDA))

However both dataspell and vs code do not support interactive widgets - that simply works in browser, Is there any IDE that supports it?

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [June 27, 2022, 7:10pm UTC](https://discourse.slicer.org/t/slicer-jupyter-docker-with-cuda/23519/6 "2022-06-27T19:10:33Z")

</div>

Thanks for sharing your results. What were the main changes that you had to do?

VS Code has lots of assumptions about your Jupyter server and kernel which are often not valid. For example, in Slicer’s Python environment the Python interpreter has a special name, we use xeus-python kernel and not the default native Python kernel - which VS Code may not be prepared for.

---

<div class="post-metadata">

### Author: ![Jakub\_Mitura](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jakub_mitura/32/8858_2.png) [@Jakub\_Mitura](https://discourse.slicer.org/u/Jakub_Mitura)
#### Post date: [June 28, 2022, 6:22am UTC](https://discourse.slicer.org/t/slicer-jupyter-docker-with-cuda/23519/7 "2022-06-28T06:22:50Z")

</div>

changed base to nvidia/cuda:11.3.1-base-ubuntu20.04

added some basic libraries like manpages-dev

installed CUDA 11.3

Changed version of the Slicer to newer

installed some python packages mainly pytorch and monai with most of its dependencies  
for convenience  
created some additional folders, added jupyterlab\_github
