Skip to main content

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 by setup() on first run via apt-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

Metadata

Release files for napari-colab 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for napari-colab 0.1.2
File Size Uploaded
napari_colab-0.1.2.tar.gz 9.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for napari-colab 0.1.2
File Interpreter ABI Platform
napari_colab-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 18.7 kB

Release files / napari_colab-0.1.2.tar.gz

Download URL napari_colab-0.1.2.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
babb4aba12ed93a19074bb8d1e39cdb4defce69f325a67632894a81f1de58c6e
BLAKE2b-256 checksum
How to use checksums
58cf7337b5e2fab33d7342bb1608021144099af9c5e10be0fffb40e0c9789d89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.8

Release files / napari_colab-0.1.2-py3-none-any.whl

Download URL napari_colab-0.1.2-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fc7594ca4b500f2fc16a498971e15902dd7a962125f6d5ee59f8d72b95eb926e
BLAKE2b-256 checksum
How to use checksums
cfd2fc8fa15c7bea0c120a5fe41e58ed6c40a0b4568ac6d62c4271531d3e1fb2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.8

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page