Skip to content

Instantly share code, notes, and snippets.

@jalogisch
Forked from tevino/fix_virtualenv
Created January 31, 2020 08:17
Show Gist options
  • Save jalogisch/96ebccd9a050a2d1c489a2c6149e549d to your computer and use it in GitHub Desktop.
Save jalogisch/96ebccd9a050a2d1c489a2c6149e549d to your computer and use it in GitHub Desktop.
Fix python virtualenv after python update
#!/usr/bin/env bash
ENV_PATH="$(dirname "$(dirname "$(which pip)")")"
SYSTEM_VIRTUALENV="$(which -a virtualenv|tail -1)"
BAD_ENV_PATHS="/usr/local"
echo "Ensure the root of the broken virtualenv:"
echo " $ENV_PATH"
if [[ -z "$ENV_PATH" ]] || [[ "$ENV_PATH" = *"$BAD_ENV_PATHS"* ]]; then
echo "The root path above doesn't seems to be a valid one."
echo "Please make sure you ACTIVATED the broken virtualenv."
echo "‼️ Exiting for your safety... (thanks @laymonk for reporting this)"
exit 1
fi
read -p "‼️ Press Enter if you are not sure (y/N) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "♻️ Removing old symbolic links......"
find "$ENV_PATH" -type l -delete -print
echo "💫 Creating new symbolic links......"
$SYSTEM_VIRTUALENV "$ENV_PATH"
echo "🎉 Done!"
fi
@jalogisch
Copy link
Author

jalogisch commented Jan 31, 2020

CAUTION: USE AT YOUR OWN RISK.

Just activate your broken virtualenv and execute this script, you can run it immediately with either curl or wget:

(via curl)

    sh <(curl -sL https://gist.githubusercontent.com/jalogisch/96ebccd9a050a2d1c489a2c6149e549d/raw/e5932f9923e57dcb41db32fe5bed9acc6d584be4/fix_virtualenv)

(via wget)

    sh <(wget -qO- https://gist.githubusercontent.com/jalogisch/96ebccd9a050a2d1c489a2c6149e549d/raw/e5932f9923e57dcb41db32fe5bed9acc6d584be4/fix_virtualenv)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment