Interactive napari viewer inside Google Colab via noVNC
Project description
napari-colab
_ ____ _ _
_ __ __ _ _ __ __ _| |/ ___|___ | | __ _| |__
| '_ \ / _` | '_ \ / _` | | | / _ \| |/ _` | '_ \
| | | | (_| | |_) | (_| | | |__| (_) | | (_| | |_) |
|_| |_|\__,_| .__/ \__,_|_|\____\___/|_|\__,_|_.__/
|_|
napari :heart: Colab — because microscopy images deserve a real viewer, even in the cloud.
Interactive napari viewer inside Google Colab via noVNC.
Warning: This package is designed exclusively for Google Colab. It relies on root access via
apt-get, a virtual framebuffer (Xvfb), and the Colab proxy to tunnel ports to your browser. It will not work on local machines, JupyterHub, or other hosted notebook services. If you can run napari locally, you should — it will be faster and more responsive.
Installation
pip install napari-colab
Note: the system packages (
xvfb,x11vnc,scrot, xcb libraries) are installed automatically bysetup()on first run viaapt-get.
Quick start
# Cell 1 — once per session
from napari_colab import setup, open_viewer, screenshot, shutdown
# Cell 2 — launch viewer (URL printed here)
viewer = open_viewer(width=1800, height=1000)
# Cell 3 — load your data
from pathlib import Path
images = sorted(Path('my_images/').glob('*.tiff'))
labels = sorted(Path('my_labels/').glob('*.tiff'))
viewer.open(images, stack=True, name='raw')
viewer.open(labels, stack=True, layer_type='labels', name='segmentation')
# Cell 4 — optional extras
viewer.dims.ndisplay = 3
viewer.camera.angles = (30, 45, 0)
screenshot() # inline preview
API
| Function | Description |
|---|---|
setup() |
Install deps, start Xvfb + x11vnc + noVNC |
open_viewer(width, height) |
Launch napari subprocess, return ViewerProxy |
screenshot() |
Capture virtual display inline in notebook |
shutdown() |
Kill napari and display helpers |
ViewerProxy
viewer.open(paths, stack=True, name='layer', layer_type='image'|'labels')
viewer.add_image(np_array, name='...', colormap='...', blending='...')
viewer.add_labels(np_array, name='...')
viewer.dims.ndisplay = 2 | 3
viewer.camera.angles = (rx, ry, rz)
viewer.camera.zoom = 1.5
viewer.reset_view()
viewer.window.resize(w, h)
How it works
Xvfb (:99) <- napari + Qt render here (software OpenGL / Mesa)
|
x11vnc <- captures framebuffer -> VNC (port 5900)
|
websockify <- VNC -> WebSocket bridge (port 6080)
|
noVNC <- web client at /vnc.html
|
Colab proxy <- tunnels port 6080 to your browser tab
napari runs in its own subprocess so the Colab kernel never crashes.
Commands (open, add_image, camera, etc.) are forwarded via a
JSON-over-TCP socket. A QTimer drains the command queue every 200 ms
on the Qt main thread — the only thread allowed to touch Qt objects.
Troubleshooting
OpenCV Qt conflict (Cellpose and similar packages)
Packages like Cellpose pull in opencv-python, which bundles its own Qt plugins. These conflict with the Qt used by napari, causing a fatal xcb plugin error:
qt.qpa.plugin: Could not load the Qt platform plugin "xcb"
napari-colab depends on opencv-python-headless (which is functionally identical but Qt-free) to avoid this. However, if you install a package that depends on opencv-python after napari-colab, pip may re-install the full OpenCV and reintroduce the conflict.
Fix:
pip uninstall -y opencv-python && pip install opencv-python-headless
Prevention: install OpenCV-dependent packages (cellpose, etc.) before napari-colab so that the headless variant wins:
pip install cellpose
pip install napari-colab
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file napari_colab-0.1.2.tar.gz.
File metadata
- Download URL: napari_colab-0.1.2.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
babb4aba12ed93a19074bb8d1e39cdb4defce69f325a67632894a81f1de58c6e
|
|
| MD5 |
6bac3d69051db4ad555d9c1b7a9f1ea5
|
|
| BLAKE2b-256 |
58cf7337b5e2fab33d7342bb1608021144099af9c5e10be0fffb40e0c9789d89
|
File details
Details for the file napari_colab-0.1.2-py3-none-any.whl.
File metadata
- Download URL: napari_colab-0.1.2-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc7594ca4b500f2fc16a498971e15902dd7a962125f6d5ee59f8d72b95eb926e
|
|
| MD5 |
96b2381f0ce83dbb6c4669ba6ca5a27b
|
|
| BLAKE2b-256 |
cfd2fc8fa15c7bea0c120a5fe41e58ed6c40a0b4568ac6d62c4271531d3e1fb2
|