Last active
December 30, 2015 10:59
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's rather hacky.