-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_python.sh
More file actions
executable file
·45 lines (37 loc) · 1.59 KB
/
setup_python.sh
File metadata and controls
executable file
·45 lines (37 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
# Script to set up the Python environment with pyenv and uv
set -e
echo "--- 🐍 Setting up Python environment ---"
# Add pyenv initialization commands to .zshrc if they are not already present (for idempotency)
if ! grep -q 'eval "$(pyenv init -)"' "${HOME}/.zshrc"; then
echo "Adding pyenv configuration to ~/.zshrc..."
echo '' >>"${HOME}/.zshrc"
echo '# pyenv setup' >>"${HOME}/.zshrc"
echo 'export PYENV_ROOT="${HOME}/.pyenv"' >>"${HOME}/.zshrc"
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >>"${HOME}/.zshrc"
echo 'eval "$(pyenv init -)"' >>"${HOME}/.zshrc"
fi
# Enable pyenv in the current shell (to use pyenv commands within the script)
export PYENV_ROOT="${HOME}/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
# Install the latest stable version of Python (e.g., 3.13 series)
LATEST_PYTHON=$(pyenv install -l | grep -E "^\s*3\.14\.[0-9]+$" | tail -n 1 | xargs)
if [ -z "$LATEST_PYTHON" ]; then
echo "❌ Error: Could not find latest Python 3.13.x version."
exit 1
fi
echo "Installing Python ${LATEST_PYTHON}..."
pyenv install --skip-existing "$LATEST_PYTHON" # Use --skip-existing for idempotency
pyenv global "$LATEST_PYTHON"
# Install uv
echo "Installing uv (the fast package manager)..."
# pip install is not idempotent, so check for existence
if ! command -v uv &>/dev/null; then
pip install uv
else
echo "uv is already installed. Skipping installation."
fi
echo "✅ Python setup complete. Current version: $(python --version)"
echo "uv is installed. Try 'uv --version'."
echo "NOTE: Please restart your terminal or run 'source ~/.zshrc' to apply changes."