1.8 KiB
1.8 KiB
add_ipykernel
Adds Python virtual environments as Jupyter ipykernel options.
Description
This script automates the creation and registration of Python environments as Jupyter kernels. It supports both conda and pip virtual environments.
Usage
./add_ipykernel.sh ENV_NAME [--create] [--verbose] [pkg1 pkg2 ...]
Arguments
ENV_NAME: Name of the environment/kernel to create or use--create: Create a new environment if it doesn't exist--verbose: Enable detailed outputpkg1 pkg2 ...: Additional packages to install
Examples
# Create new conda environment and register as kernel
./add_ipykernel.sh ds_env --create python=3.11 pandas
# Use existing environment
./add_ipykernel.sh ds_env --verbose
# Create pip venv with specific packages
./add_ipykernel.sh myproject --create numpy scipy matplotlib
Package Manager Detection
The script automatically detects the appropriate package manager:
- conda: Used if environment exists in conda or if
environment.yml/conda.yamlis present - pip: Used if
requirements.txtorpyproject.tomlexists, or if already in a virtual environment
What It Does
- Detects package manager (conda or pip)
- Creates environment if
--createflag is used - Activates the environment
- Installs
ipykernelif not present - Registers the environment as a Jupyter kernel with display name
Python (ENV_NAME)
Requirements
- conda (for conda environments) OR python3 with venv (for pip environments)
- Jupyter installed (for kernel registration)
Notes
- Kernels are registered in user space (
--userflag) - After registration, the kernel appears in Jupyter as "Python (ENV_NAME)"
- If environment already exists, just registers it without modifying packages