-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist-python.sh
More file actions
65 lines (55 loc) · 1.84 KB
/
list-python.sh
File metadata and controls
65 lines (55 loc) · 1.84 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/zsh
export PATH="/usr/local/bin:/usr/bin:/bin:/opt/homebrew/bin:$PATH"
echo "\n🔍 Checking user-installed Python distributions..."
echo ""
typeset -a python_paths
add_path() {
local p="$1"
[[ -x "$p" ]] || return
for existing in "${python_paths[@]}"; do
[[ "$existing" == "$p" ]] && return
done
python_paths+="$p"
}
# 1️⃣ Detect Homebrew Python
brew_python=$(which python3 2>/dev/null)
if [[ -n "$brew_python" && "$brew_python" == *"homebrew"* ]]; then
add_path "$brew_python"
fi
# 2️⃣ Detect Conda / Miniconda / Anaconda / Miniforge / Mambaforge
for conda_dir in "$HOME/miniforge3" "$HOME/mambaforge" "$HOME/anaconda3" "$HOME/miniconda3" "$HOME/opt/miniconda3" "$HOME/opt/anaconda3"; do
[[ -x "$conda_dir/bin/python" ]] && add_path "$conda_dir/bin/python"
done
# 3️⃣ Detect pyenv versions (if installed)
if command -v pyenv >/dev/null 2>&1; then
for v in $(pyenv versions --bare 2>/dev/null); do
pyenv_python="$HOME/.pyenv/versions/$v/bin/python"
[[ -x "$pyenv_python" ]] && add_path "$pyenv_python"
done
fi
# 4️⃣ Display results
echo "📦 User Python Installations Found:"
echo "-----------------------------------"
if (( ${#python_paths[@]} == 0 )); then
echo "No user-installed Pythons found."
else
for path in "${python_paths[@]}"; do
version=$("$path" --version 2>&1)
if [[ "$path" == *"miniforge3"* ]]; then
tag="(Miniforge)"
elif [[ "$path" == *"mambaforge"* ]]; then
tag="(Mambaforge)"
elif [[ "$path" == *"anaconda3"* || "$path" == *"miniconda3"* ]]; then
tag="(Anaconda/Miniconda)"
elif [[ "$path" == *"pyenv"* ]]; then
tag="(pyenv)"
elif [[ "$path" == *"/opt/homebrew"* ]]; then
tag="(Homebrew)"
else
tag=""
fi
printf "%-70s %s %s\n" "$path" "$version" "$tag"
done
fi
echo "-----------------------------------"
echo "✅ Done.\n"