Skip to content

Instantly share code, notes, and snippets.

@tehmas
Created July 9, 2025 07:48
Show Gist options
  • Select an option

  • Save tehmas/a6be4a58d25c1c9217bcdeab5eaa4fbe to your computer and use it in GitHub Desktop.

Select an option

Save tehmas/a6be4a58d25c1c9217bcdeab5eaa4fbe to your computer and use it in GitHub Desktop.
#!/bin/bash
# ---------------------------------------------------------------
# Data Analyst Environment Setup Script (macOS)
# ---------------------------------------------------------------
#
# This script installs the following:
# - Homebrew (package manager for macOS)
# - pyenv (Python version manager)
# - Python 3.13.0 via pyenv
# - pipx (isolated Python tool installer)
# - Jupyter Notebook via pipx
# - Visual Studio Code (Apple Silicon or Intel based on CPU)
# - VS Code extensions for Data Analysts:
# - Python (ms-python.python)
# - Jupyter (ms-toolsai.jupyter)
# - Pylance (ms-python.vscode-pylance)
# - Rainbow CSV (mechatroner.rainbow-csv)
# - Python Environment Manager (donjayamanne.python-environment-manager)
#
# To run this script in one line from Terminal:
# chmod +x setup_data_env.sh && ./setup_data_env.sh
#
# All environment changes are applied immediately — no terminal restart needed.
set -e
GREEN='\033[0;32m'
NC='\033[0m'
echo -e "${GREEN}Installing Homebrew...${NC}"
if ! command -v brew >/dev/null 2>&1; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
# Ensure Homebrew is available in the session
eval "$(/opt/homebrew/bin/brew shellenv 2>/dev/null || /usr/local/bin/brew shellenv)"
# Determine user's shell config
SHELL_PROFILE=""
if [[ "$SHELL" == */zsh ]]; then SHELL_PROFILE="$HOME/.zprofile"
elif [[ "$SHELL" == */bash ]]; then SHELL_PROFILE="$HOME/.bash_profile"
else SHELL_PROFILE="$HOME/.profile"
fi
# Ensure Homebrew env is persisted
if ! grep -q 'brew shellenv' "$SHELL_PROFILE"; then
echo "eval \"\$($(brew --prefix)/bin/brew shellenv)\"" >> "$SHELL_PROFILE"
fi
echo -e "${GREEN}Installing pyenv...${NC}"
brew install pyenv
# Ensure pyenv config is in shell profile
if ! grep -q 'pyenv init' "$SHELL_PROFILE"; then
echo -e "\n# Pyenv Configuration" >> "$SHELL_PROFILE"
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> "$SHELL_PROFILE"
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> "$SHELL_PROFILE"
echo 'eval "$(pyenv init --path)"' >> "$SHELL_PROFILE"
echo 'eval "$(pyenv init -)"' >> "$SHELL_PROFILE"
fi
# Apply pyenv config immediately
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
echo -e "${GREEN}Installing Python 3.13.0 with pyenv...${NC}"
pyenv install 3.13.0 || echo -e "${GREEN}Python 3.13.0 already installed.${NC}"
pyenv global 3.13.0
echo -e "${GREEN}Installing pipx...${NC}"
brew install pipx
pipx ensurepath
echo -e "${GREEN}Installing Jupyter Notebook...${NC}"
pipx install notebook || echo -e "${GREEN}Jupyter may already be installed via pipx.${NC}"
echo -e "${GREEN}Installing Visual Studio Code...${NC}"
ARCH=$(uname -m)
if [[ "$ARCH" == "arm64" ]]; then
VSCODE_URL="https://update.code.visualstudio.com/latest/darwin-arm64/stable"
else
VSCODE_URL="https://update.code.visualstudio.com/latest/darwin/stable"
fi
TMP_DIR=$(mktemp -d)
curl -L "$VSCODE_URL" -o "$TMP_DIR/VSCode.zip"
unzip -q "$TMP_DIR/VSCode.zip" -d /Applications
rm -rf "$TMP_DIR"
# Add VS Code to PATH if not already there
export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
echo -e "${GREEN}Installing VS Code extensions...${NC}"
EXTENSIONS=(
ms-python.python
ms-toolsai.jupyter
ms-python.vscode-pylance
mechatroner.rainbow-csv
donjayamanne.python-environment-manager
)
for EXT in "${EXTENSIONS[@]}"; do
code --install-extension "$EXT" || echo -e "${GREEN}Extension $EXT may already be installed.${NC}"
done
echo -e "${GREEN}✔ Setup complete!${NC}"
echo -e "Test your tools with the following commands:"
echo -e " python --version"
echo -e " jupyter notebook"
echo -e " code ."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment