Skip to content

Instantly share code, notes, and snippets.

@EconoBen
Last active June 29, 2025 05:39
Show Gist options
  • Select an option

  • Save EconoBen/b564a2a9498eea12df0fad5fd1aea19f to your computer and use it in GitHub Desktop.

Select an option

Save EconoBen/b564a2a9498eea12df0fad5fd1aea19f to your computer and use it in GitHub Desktop.
[workshop] category:python tags:python,virtualenv,productivity,bash - Python Virtual Environment Quick Setup
# Add to ~/.bashrc or ~/.zshrc
# Create and activate a Python virtual environment
venv() {
local env_name="${1:-venv}"
if [ -d "$env_name" ]; then
echo "Activating existing environment: $env_name"
source "$env_name/bin/activate"
else
echo "Creating new environment: $env_name"
python3 -m venv "$env_name"
source "$env_name/bin/activate"
pip install --upgrade pip
fi
}
# Deactivate and remove virtual environment
venv-remove() {
local env_name="${1:-venv}"
if [ -n "$VIRTUAL_ENV" ]; then
deactivate
fi
if [ -d "$env_name" ]; then
rm -rf "$env_name"
echo "Removed environment: $env_name"
else
echo "Environment not found: $env_name"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment