Last active
June 29, 2025 05:39
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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