Skip to content

Instantly share code, notes, and snippets.

@lukauskas
Last active December 18, 2015 05:49
Show Gist options
  • Save lukauskas/5735144 to your computer and use it in GitHub Desktop.
Save lukauskas/5735144 to your computer and use it in GitHub Desktop.
Script to install python 2.7 to a local location together with virtualenv
#/bin/bash
# Get installation prefix from the args
PREFIX=$HOME # Default to home
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
# This is needed to have Tkinter package in python -- at least a primitive
# GUI backend matplotlib could use
echo "Installing tcl/tk"
wget http://prdownloads.sourceforge.net/tcl/tcl8.6.0-src.tar.gz
wget http://prdownloads.sourceforge.net/tcl/tk8.6.0-src.tar.gz
tar xvf tcl8.6.0-src.tar.gz
tar xvf tk8.6.0-src.tar.gz
echo "Installing tcl"
cd $TEMP_DIR/tcl8.6.0/unix
./configure --prefix="$PREFIX" --exec-prefix="$PREFIX"
make install
echo "Installing tk"
cd $TEMP_DIR/tk8.6.0/unix
./configure --prefix="$PREFIX" --exec-prefix="$PREFIX"
make install
cd $TEMP_DIR
echo "export LD_LIBRARY_PATH=$PREFIX/lib:$LD_LIBRARY_PATH" >> $ACTIVATE_SCRIPT
source $ACTIVATE_SCRIPT
echo "export LDFLAGS=-L${PREFIX}/lib" >> setup_exports.sh
echo "export CPPFLAGS=-I${PREFIX}/include" >> setup_exports.sh
echo "export CFLAGS=-I${PREFIX}/include" >> setup_exports.sh
source setup_exports.sh
# Install python
wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
tar xvf Python-2.7.3.tgz
cd Python-2.7.3
./configure
make altinstall prefix="$PREFIX" exec-prefix="$PREFIX"
if [ ! -f $PREFIX/bin/python ]; then
ln -s $PREFIX/bin/python2.7 $PREFIX/bin/python
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 --no-check-certificate https://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg#md5=fe1f997bc722265116870bc7919059ea
sh ./setuptools-0.6c11-py2.7.egg
# Install virtualenv and its wrapper
easy_install-2.7 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