Last active
August 29, 2015 14:14
-
-
Save lukauskas/08b11f1cde505d32746c to your computer and use it in GitHub Desktop.
install-python 2.7.9 script
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 | |
# Get installation prefix from the args | |
VERSION=2.7.9 | |
PREFIX=$HOME/python${VERSION} # Default to home/python-2.7.9 | |
if [ -n "$1" ]; then | |
PREFIX=$1 | |
if [ ! -d "$PREFIX" ]; then | |
mkdir $PREFIX | |
fi | |
PREFIX=`cd $PREFIX; pwd` # Convert to absolute path | |
fi | |
echo "Installing python to $PREFIX" | |
ACTIVATE_SCRIPT="$PREFIX/activate.sh" | |
touch $ACTIVATE_SCRIPT | |
chmod +x $ACTIVATE_SCRIPT | |
TEMP_DIR=`mktemp -d /tmp/python_install.XXXXXXXX` | |
echo "Creating a temporary directory $TEMP_DIR" | |
cd $TEMP_DIR | |
# Install python | |
wget http://www.python.org/ftp/python/${VERSION}/Python-${VERSION}.tgz | |
tar xf Python-${VERSION}.tgz | |
cd Python-${VERSION} | |
./configure | |
make altinstall prefix="$PREFIX" exec-prefix="$PREFIX" | |
if [ ! -f $PREFIX/bin/python ]; then | |
ln -s $PREFIX/bin/python2.7 $PREFIX/bin/python | |
fi | |
if [ ! -f $PREFIX/bin/python2 ]; then | |
ln -s $PREFIX/bin/python2.7 $PREFIX/bin/python2 | |
fi | |
# Create activate script | |
echo "export PATH=$PREFIX/bin:\$PATH" >> $ACTIVATE_SCRIPT | |
echo "export PYTHONPATH=$PREFIX/lib/python2.7/site-packages/:\$PYTHONPATH" >> $ACTIVATE_SCRIPT | |
# Activate the environment here as well | |
source $ACTIVATE_SCRIPT | |
# Download and install setuptools | |
wget https://bootstrap.pypa.io/ez_setup.py | |
$PREFIX/bin/python ez_setup.py | |
# Install virtualenv and its wrapper | |
easy_install-2.7 pip | |
pip install virtualenv virtualenvwrapper | |
echo "source $PREFIX/bin/virtualenvwrapper.sh" >> $ACTIVATE_SCRIPT | |
# Cleanup | |
rm -rf $TEMP_DIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment