Skip to content

Instantly share code, notes, and snippets.

@seletz
Last active December 30, 2015 10:59
Show Gist options
  • Select an option

  • Save seletz/7820036 to your computer and use it in GitHub Desktop.

Select an option

Save seletz/7820036 to your computer and use it in GitHub Desktop.
bash script to fix a br0ken python virtual env after a python upgrade. Usable probably only on OS X. This script uses a known-good „p27“ virtual env — recreate this manually.
#!/bin/bash
#set -x
VENV=$1
VH=$VIRTUALENV_ROOT/$VENV
# Adjust this to the actual python version you want to convert your venv to
PYTHON_ROOT=/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7
test -d "$VIRTUALENV_ROOT/p27" || {
echo "need a p27 venv to copy stuff from. This needs to be a working venv."
exit 12
}
test -d $VH || {
echo "$VH?"
exit 10
}
cd $VH
test -L "include/python2.7" || {
echo "not python2.7"
exit 11
}
echo "fixing .Python"
(
ls -la .Python
ln -sf $PYTHON_ROOT/Python .Python
ls -la .Python
)
echo "fixing bin"
(
cd bin
cp $VIRTUALENV_ROOT/p27/bin/python .
)
echo "fixing includes"
(
cd include
ls -la python2.7
ln -sf $PYTHON_ROOT/include/python2.7 python2.7
ls -la python2.7
)
echo "fixing lib"
(
cd lib/python2.7
rm -f *.pyc
for pf in *; do
test -L $pf && {
ln -sf $PYTHON_ROOT/lib/python2.7/$pf $pf
}
done
cp $VIRTUALENV_ROOT/p27/lib/python2.7/site.py .
cp $VIRTUALENV_ROOT/p27/lib/python2.7/orig-prefix.txt .
)
# vim: set ts=4 sw=4 nolist expandtab:
@seletz
Copy link
Copy Markdown
Author

seletz commented Dec 6, 2013

It's rather hacky.

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