Skip to main content

A Python environment switcher for Google Colab

Project description

Colab Environment Switcher

A simple Python library to easily switch Python versions in Google Colab environments.

Features

  • 🚀 Quick Python version switching in Google Colab
  • 📦 Automatic pip installation for the new Python version
  • ✅ Simple one-line API
  • 🔧 Optional uv package manager installation
  • 🔄 Auto restart runtime to apply changes (new in 0.1.2.post2)

Installation

From PyPI (Recommended)

# Install directly from PyPI
!pip install colab-env-switcher

From GitHub Release

# Install from GitHub Release wheel file
pip install https://github.com/911218sky/colab-env-switcher/releases/latest/download/colab_env_switcher-0.1.0-py3-none-any.whl

From GitHub Source

# Install latest version from GitHub source
!pip install git+https://github.com/911218sky/colab-env-switcher.git

Local Development

pip install -e .

Usage

Basic Usage

from colab_env_switcher import switch_python_version

# Switch to Python 3.11 (will auto restart runtime)
switch_python_version("3.11")

With uv Package Manager

from colab_env_switcher import switch_python_version

# Switch to Python 3.10 and install uv
switch_python_version("3.10", install_uv=True)

Disable Auto Restart

from colab_env_switcher import switch_python_version

# Switch without auto restart (useful if you want to install packages first)
switch_python_version("3.12", auto_restart=False)

# Then manually restart later:
# from google.colab import runtime; runtime.unassign()

Parameters

Parameter Type Default Description
version str required Python version to switch to (e.g., "3.11")
install_uv bool False Install uv package manager after switching
auto_restart bool True Automatically restart runtime after switching

Supported Python Versions

  • Python 3.7
  • Python 3.8
  • Python 3.9
  • Python 3.10
  • Python 3.11
  • Python 3.12
  • Python 3.13 (if available)
  • Python 3.14 (experimental, if available)

Note: Newer Python versions (3.13+) may have limited package availability. For production use, we recommend Python 3.10-3.12.

Example in Colab

# Install the library
!pip install colab-env-switcher

# Import and use
from colab_env_switcher import switch_python_version

# Switch to Python 3.11 (runtime will auto restart)
switch_python_version("3.11")

# After restart, verify the version
import sys
print(sys.version)

# Reinstall your required packages
!pip install numpy pandas matplotlib

Important Notes

⚠️ After switching Python versions:

  • The runtime will automatically restart (unless auto_restart=False)
  • After restart, sys.version will show the correct Python version
  • You need to reinstall all required packages

License

MIT License

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

colab_env_switcher-0.1.2.post2.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

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

colab_env_switcher-0.1.2.post2-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file colab_env_switcher-0.1.2.post2.tar.gz.

File metadata

File hashes

Hashes for colab_env_switcher-0.1.2.post2.tar.gz
Algorithm Hash digest
SHA256 185eaa04159f09614fce21a80536570314c16b5aa372396dd4463da548eb7dd7
MD5 cbd052beca2b44550369fd157ef3408c
BLAKE2b-256 f4fbaaa5f6bba8d2e8e2d4ddddf30c37ca1a9dfe5db34b232473da45c67e2dd2

See more details on using hashes here.

File details

Details for the file colab_env_switcher-0.1.2.post2-py3-none-any.whl.

File metadata

File hashes

Hashes for colab_env_switcher-0.1.2.post2-py3-none-any.whl
Algorithm Hash digest
SHA256 6b1667dd5d837c4cd3041d82f2ffd3f510abdf3112360efed685596c1aa604c9
MD5 f8eea3729fe7aff964c8fe6dd21fad08
BLAKE2b-256 597f1a6b30267f5f3dbae7dfb181fc9022f768533c57d3fbe0dde1f3bf7db3dd

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