Skip to main content

Jupyterlab extension to detect notebook kernels similarly to how nb_conda_kernel does

Project description

nb_venv_kernels

GitHub Actions npm version PyPI version Total PyPI downloads JupyterLab 4 Brought To You By KOLOMOLO

Use Python virtual environments as Jupyter kernels. Discovers and registers kernels from venv, uv, and conda environments in JupyterLab's kernel selector.

UV and Conda virtual environments co-exist and are properly discovered

Features

  • Unified kernel discovery - conda, venv, and uv environments in one kernel selector
  • Auto-detection - distinguishes uv from venv via pyvenv.cfg
  • Smart ordering - current environment first, then conda, uv, venv, system
  • Drop-in replacement - replaces nb_conda_kernels while preserving all conda functionality
  • CLI management - register, unregister, and list environments
  • Zero config - auto-enables on install, works immediately

Install

pip install nb_venv_kernels

The extension installs itself as the default kernel spec manager via jupyter_config.json. If nb_conda_kernels is installed, nb_venv_kernels takes precedence and includes all conda kernel discovery functionality.

Usage

Virtual environments require ipykernel installed to be discoverable. The ipykernel package creates the kernel spec at {env}/share/jupyter/kernels/*/kernel.json.

# In your virtual environment
pip install ipykernel

Then register the environment:

nb_venv_kernels register /path/to/.venv
nb_venv_kernels list
nb_venv_kernels unregister /path/to/.venv

Manage Jupyter configuration:

nb_venv_kernels config enable     # Enable VEnvKernelSpecManager
nb_venv_kernels config disable    # Disable VEnvKernelSpecManager
nb_venv_kernels config show       # Show current config status

Registered environments with ipykernel appear in JupyterLab's kernel selector.

Environment Registries

Environments are registered in separate files based on their source:

  • venv: ~/.venv/environments.txt
  • uv: ~/.uv/environments.txt
  • conda: ~/.conda/environments.txt + global environments from conda env list

The register command auto-detects uv environments via pyvenv.cfg and writes to the appropriate registry.

How It Works

flowchart LR
    subgraph Registries
        VENV[~/.venv/environments.txt]
        UV[~/.uv/environments.txt]
        CONDA_REG[~/.conda/environments.txt]
    end

    subgraph Auto-Discovery
        CONDA_ENV[conda env list]
        PYVENV[pyvenv.cfg]
    end

    subgraph Discovery
        KSPM[VEnvKernelSpecManager]
        CKSPM[CondaKernelSpecManager]
    end

    VENV --> KSPM
    UV --> KSPM
    PYVENV -.->|detects uv| UV
    CONDA_REG --> CKSPM
    CONDA_ENV --> CKSPM
    CKSPM --> KSPM
    KSPM --> JL[JupyterLab Kernel Selector]

    style VENV stroke:#10b981,stroke-width:2px
    style UV stroke:#a855f7,stroke-width:2px
    style CONDA_REG stroke:#f59e0b,stroke-width:2px
    style CONDA_ENV stroke:#f59e0b,stroke-width:2px
    style PYVENV stroke:#6b7280,stroke-width:2px
    style KSPM stroke:#3b82f6,stroke-width:3px
    style CKSPM stroke:#f59e0b,stroke-width:2px
    style JL stroke:#0284c7,stroke-width:3px
  • Scans {path}/share/jupyter/kernels/*/kernel.json for each registered environment
  • Configures kernel to use venv's python directly with VIRTUAL_ENV and PATH environment variables
  • Kernel order: current environment first, then conda, uv, venv, system
  • Caches results for 60 seconds
  • config enable backs up existing config, config disable restores from backup

Configuration

Optional settings in jupyter_server_config.py:

c.VEnvKernelSpecManager.venv_only = True                      # Hide system/conda kernels
c.VEnvKernelSpecManager.env_filter = r"\.tox|\.nox"           # Exclude by pattern
c.VEnvKernelSpecManager.name_format = "{language} [{source} env:{environment}]"  # Default format

Display name variables: {language}, {environment}, {source} (uv/venv), {kernel}, {display_name}

Uninstall

pip uninstall nb_venv_kernels

After uninstall, nb_conda_kernels (if installed) will resume handling kernel discovery.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nb_venv_kernels-1.0.9.tar.gz (550.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nb_venv_kernels-1.0.9-py3-none-any.whl (27.6 kB view details)

Uploaded Python 3

File details

Details for the file nb_venv_kernels-1.0.9.tar.gz.

File metadata

  • Download URL: nb_venv_kernels-1.0.9.tar.gz
  • Upload date:
  • Size: 550.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for nb_venv_kernels-1.0.9.tar.gz
Algorithm Hash digest
SHA256 13cc24dc21c79e672e23bad987935fcc453c7c582a5ac2e3e6d265e0103364ed
MD5 decd91b81358f8fb843e3ccb6ee278db
BLAKE2b-256 1c028f17f096489733c305bcf682f527ef1016bced7f21a28439295b64f4c2fa

See more details on using hashes here.

File details

Details for the file nb_venv_kernels-1.0.9-py3-none-any.whl.

File metadata

File hashes

Hashes for nb_venv_kernels-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 b1dc3b81b9c652b51eb815f1342d0f04ae21e214efd8cfb911a54338be9c8d6b
MD5 80e5c76684fec73dfd128c7ac72fc55c
BLAKE2b-256 6c24d9d19de0f5b29a5d064c0c17da174808c7fc2beb061a0ee52e30d9bb5f6a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page