ipykernel

7.2.0 · active · verified Sat Mar 28

ipykernel provides the IPython kernel, which serves as the Python execution backend for Jupyter Notebooks, JupyterLab, and other Jupyter frontends. It facilitates interactive Python development, supports rich media outputs, and enables seamless code sharing within these environments. The current stable version is 7.2.0, and the project maintains an active development and release cadence.

Warnings

Install

Imports

Quickstart

The primary use case for ipykernel is to provide a Python execution environment for Jupyter frontends. This quickstart demonstrates how to install ipykernel and register it as a new kernel in your current Python environment, making it available in Jupyter Notebook or JupyterLab. It's best practice to perform this within an activated virtual environment.

import subprocess
import sys
import os

# Ensure ipykernel is installed in the current environment
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'ipykernel'])

# Define a unique name for your kernel (e.g., based on virtual environment name)
env_name = os.environ.get('VIRTUAL_ENV', 'default_env').split(os.sep)[-1]
display_name = f"Python ({env_name.replace('_', ' ').title()} Environment)"

# Register the kernel with Jupyter
try:
    subprocess.check_call([
        sys.executable, '-m', 'ipykernel', 'install',
        '--user', f'--name={env_name}', f'--display-name={display_name}'
    ])
    print(f'Successfully registered Jupyter kernel: "{display_name}" (name: {env_name})')
    print('To use it, launch Jupyter Notebook/Lab and select this kernel for a new notebook.')
    print('You can verify installed kernels with: jupyter kernelspec list')
except subprocess.CalledProcessError as e:
    print(f'Failed to register kernel: {e}')
    print('Ensure Jupyter is installed (pip install notebook or pip install jupyterlab).')

view raw JSON →