Created
October 24, 2025 20:48
-
-
Save toasterparty/4f5f70a32d8c30b0d29925eb34251ba7 to your computer and use it in GitHub Desktop.
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
| # Usage: | |
| # venv_setup <venv path> [<python version>] [<requirements.txt path>] | |
| # | |
| # If <python version> is left "", then the default python interpreter | |
| # will be used, otherwise provide a number like "3.11" | |
| # | |
| venv_setup() { | |
| local VENV_DIR="$1" | |
| local PY_VER="${2-}" | |
| local REQUIREMENTS_TXT="$3" | |
| local PY="python$PY_VER" | |
| local VENV_PY="$VENV_DIR/bin/python" | |
| "$PY" --version &> /dev/null || (echo "Error: '$PY' not installed" && exit 1) | |
| if ! "$VENV_PY" --version &> /dev/null; then | |
| if [ -d "$VENV_DIR" ]; then | |
| echo "Removing existing virtual enviornment..." | |
| rm -rf "$VENV_DIR" | |
| fi | |
| echo "Creating new virtual enviornment..." | |
| "$PY" -m venv "$VENV_DIR" | |
| fi | |
| if [[ -n "$REQUIREMENTS_TXT" && -f "$REQUIREMENTS_TXT" ]]; then | |
| echo "Updating packages..." | |
| "$VENV_PY" -m pip install -q --upgrade pip | |
| "$VENV_PY" -m pip install -q -r "$REQUIREMENTS_TXT" | |
| fi | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment