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.post3.tar.gz (12.4 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.post3-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for colab_env_switcher-0.1.2.post3.tar.gz
Algorithm Hash digest
SHA256 e9b5d0b2e33537c489a3b3493dd21f229f9b9b23f7d6e443a36a686341757924
MD5 90088abbaeafe75ffd2d4023d6af2edd
BLAKE2b-256 106857d896e3831471715d48d7c60b296eef04ace9db07cfbc02c3e78fabeaab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for colab_env_switcher-0.1.2.post3-py3-none-any.whl
Algorithm Hash digest
SHA256 3ea51271e9c5071f11186926c381e760e10e65b3f6f0e055e3e21db36d8e08d0
MD5 585a824b36db2363e7560ec9f32c9026
BLAKE2b-256 5a8971ec17d0c871d272dcab5b40ea208f1b2d337b81788aa14b4feea3af914f

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