Skip to content

Instantly share code, notes, and snippets.

@cloudcap10
Forked from felipealfonsog/fix-pip.sh
Created October 9, 2025 14:40
Show Gist options
  • Save cloudcap10/c1022afa24da4634e66846d7a62c9ac2 to your computer and use it in GitHub Desktop.
Save cloudcap10/c1022afa24da4634e66846d7a62c9ac2 to your computer and use it in GitHub Desktop.
Removing Python's EXTERNALLY-MANAGED lock
#!/usr/bin/env bash
echo "──────────────────────────────────────────────"
echo " Removing Python's EXTERNALLY-MANAGED lock "
echo "──────────────────────────────────────────────"
echo "* Developed and engineered by:"
echo "* Felipe Alfonso Gonzalez <[email protected]>"
echo "* Computer Science Engineer"
echo "* Chile"
echo "------------------------------------------------"
echo "* Find me on GitHub: github.com/felipealfonsog"
echo "* License: MIT & BSD v3 - Restrictive by author"
echo "──────────────────────────────────────────────"
show_progress() {
local duration=$1
local interval=0.08
local steps
steps=$(awk "BEGIN {printf \"%d\", $duration / $interval}")
local i=0
while [ $i -le $steps ]; do
local progress=$(( i * 100 / (steps>0 ? steps : 1) ))
local filled=$(( progress * 50 / 100 ))
local bar=""
for ((j=0; j<filled; j++)); do bar+="="; done
for ((j=filled; j<50; j++)); do bar+=" "; done
printf "\r[%s] %3d%%" "$bar" "$progress"
sleep $interval
((i++))
done
echo
}
search_paths=(
"/opt/homebrew"
"/usr/local/Cellar"
"/usr/lib"
"/usr/local/lib"
"/lib"
"/lib64"
)
found_files=()
echo
echo "πŸ” Searching for EXTERNALLY-MANAGED files in common paths..."
show_progress 1.6
for base in "${search_paths[@]}"; do
if [ -d "$base" ]; then
while IFS= read -r -d $'\0' file; do
found_files+=("$file")
done < <(find "$base" -type f -name "EXTERNALLY-MANAGED" -print0 2>/dev/null)
fi
done
if [ ${#found_files[@]} -eq 0 ]; then
echo
echo "No EXTERNALLY-MANAGED files found in predefined paths."
echo "Searching system-wide (may take a while)..."
show_progress 3.2
while IFS= read -r -d $'\0' file; do
found_files+=("$file")
done < <(find / -type f -name "EXTERNALLY-MANAGED" -print0 2>/dev/null)
fi
if [ ${#found_files[@]} -gt 0 ]; then
echo
echo "🧹 Found ${#found_files[@]} file(s). Renaming now..."
total=${#found_files[@]}
count=0
for file in "${found_files[@]}"; do
((count++))
percent=$(( count * 100 / total ))
filled=$(( percent * 50 / 100 ))
bar=""
for ((j=0; j<filled; j++)); do bar+="="; done
for ((j=filled; j<50; j++)); do bar+=" "; done
printf "\r[%s] %3d%% - %s" "$bar" "$percent" "$(basename "$file")"
if sudo mv -- "$file" "${file}_"; then
printf " βœ…\n"
else
printf " ❌ (failed)\n"
fi
done
echo
echo "βœ… All EXTERNALLY-MANAGED files processed."
else
echo
echo "ℹ️ No EXTERNALLY-MANAGED files were found on this system."
fi
echo "──────────────────────────────────────────────"
#!/usr/bin/env bash
echo "──────────────────────────────────────────────"
echo " Removing Python's EXTERNALLY-MANAGED lock "
echo "──────────────────────────────────────────────"
echo "* Developed and engineered by:"
echo "* Felipe Alfonso Gonzalez <[email protected]>"
echo "* Computer Science Engineer"
echo "* Chile"
echo "------------------------------------------------"
echo "* Find me on GitHub: github.com/felipealfonsog"
echo "* License: MIT & BSD v3 - Restrictive by author"
echo "──────────────────────────────────────────────"
search_paths=(
"/opt/homebrew"
"/usr/local/Cellar"
"/usr/lib"
"/usr/local/lib"
"/lib"
"/lib64"
)
found_files=()
# FunciΓ³n para buscar archivos en paths predefinidos
search_in_paths() {
echo
echo "πŸ” Searching in common paths..."
for base in "${search_paths[@]}"; do
if [ -d "$base" ]; then
while IFS= read -r -d $'\0' file; do
found_files+=("$file")
done < <(find "$base" -type f -name "EXTERNALLY-MANAGED" -print0 2>/dev/null)
fi
done
}
# FunciΓ³n para buscar system-wide con spinner
search_system_wide() {
echo
echo "πŸ” Searching system-wide (may take a while)..."
temp_file=$(mktemp)
find / -type f -name "EXTERNALLY-MANAGED" -print0 2>/dev/null > "$temp_file" &
pid=$!
spinner="/|\\-"
i=0
while kill -0 $pid 2>/dev/null; do
i=$(( (i+1) % 4 ))
printf "\r%c Searching..." "${spinner:$i:1}"
sleep 0.1
done
wait $pid
echo
while IFS= read -r -d $'\0' file; do
found_files+=("$file")
done < "$temp_file"
rm -f "$temp_file"
}
# Buscar primero en paths predefinidos
search_in_paths
# Si no se encontrΓ³ nada, buscar system-wide
if [ ${#found_files[@]} -eq 0 ]; then
search_system_wide
fi
# Renombrar archivos encontrados
if [ ${#found_files[@]} -gt 0 ]; then
echo
echo "🧹 Found ${#found_files[@]} file(s). Renaming now..."
total=${#found_files[@]}
count=0
for file in "${found_files[@]}"; do
((count++))
sudo mv -- "$file" "${file}_"
echo "[$count/$total] Renamed: $file"
done
echo
echo "βœ… All EXTERNALLY-MANAGED files processed."
else
echo
echo "ℹ️ No EXTERNALLY-MANAGED files were found on this system."
fi
echo "──────────────────────────────────────────────"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment