|
#!/bin/bash |
|
|
|
set -e |
|
# Source: http://toomuchdata.com/2012/06/25/how-to-install-python-2-7-3-on-centos-6-2/ |
|
# Install stuff # |
|
################# |
|
if [ -z $1 ]; then |
|
echo "set the prefix to install" |
|
echo "for example: $0 /usr/local/python2.7" |
|
exit |
|
fi |
|
# Install development tools and some misc. necessary packages |
|
yum -y groupinstall "Development tools" |
|
yum -y install zlib-devel # gen'l reqs |
|
yum -y install bzip2-devel openssl-devel ncurses-devel # gen'l reqs |
|
yum -y install mysql-devel # req'd to use MySQL with python ('mysql-python' package) |
|
yum -y install libxml2-devel libxslt-devel # req'd by python package 'lxml' |
|
yum -y install unixODBC-devel # req'd by python package 'pyodbc' |
|
yum -y install sqlite sqlite-devel # you will be sad if you don't install this before compiling python, and later need it. |
|
# Alias shasum to == sha1sum (will prevent some people's scripts from breaking) |
|
echo 'alias shasum="sha1sum"' >> $HOME/.bashrc |
|
# Install Python 2.7.4 (do NOT remove 2.6, by the way) |
|
wget http://www.python.org/ftp/python/2.7.4/Python-2.7.4.tar.bz2 |
|
tar xf Python-2.7.4.tar.bz2 |
|
cd Python-2.7.4 |
|
./configure --prefix=$1 |
|
make && make altinstall |
|
# Install distribute |
|
wget --no-check-certificate http://pypi.python.org/packages/source/d/distribute/distribute-0.6.27.tar.gz |
|
tar xf distribute-0.6.27.tar.gz |
|
cd distribute-0.6.27 |
|
$1/bin/python2.7 setup.py install |
|
# Install virtualenv and virtualenvwrapper |
|
# Once you make your first virtualenv, you'll have 'pip' in there. |
|
# I got bitten by trying to install a system-wide (i.e. Python 2.6) version of pip; |
|
# it was clobbering my access to pip from within virtualenvs, and it was a bad scene. |
|
# So these commands will install virtualenv/virtualenvwrapper the old school way, |
|
# just so you can make yourself a virtualenv, with pip, and then do everything Python-related |
|
# that you need to do, from in there. |
|
wget --no-check-certificate https://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.9.1.tar.gz#md5=07e09df0adfca0b2d487e39a4bf2270a |
|
tar -xvzf virtualenv-1.9.1.tar.gz |
|
cd virtualenv-1.9.1 |
|
$1/bin/python2.7 setup.py install |
|
cd .. |
|
wget --no-check-certificate https://pypi.python.org/packages/source/v/virtualenvwrapper/virtualenvwrapper-4.0.tar.gz#md5=78df3b40735e959479d9de34e4b8ba15 |
|
tar -xvzf virtualenvwrapper-* |
|
cd virtualenvwrapper-4.0 |
|
$1/bin/python2.7 setup.py install |
|
|
|
echo 'export WORKON_HOME=~/Envs' >> $HOME/.bashrc # Change this directory if you don't like it |
|
echo 'export PATH=$PATH:'$1/bin >> $HOME/.bashrc |
|
echo "export VIRTUALENVWRAPPER_PYTHON=$1/bin/python2.7" >> $HOME/.bashrc |
|
. $HOME/.bashrc |
|
mkdir -p $WORKON_HOME |
|
echo "source $1/bin/virtualenvwrapper.sh" >> $HOME/.bashrc |
|
. $HOME/.bashrc |
|
|
|
|
|
# Extra stuff # |
|
############### |
|
# Add EPEL repo (more details at cyberciti.biz/faq/fedora-sl-centos-redhat6-enable-epel-repo/) |
|
if [ ! -f /etc/yum.repos.d/epel.repo ]; then |
|
echo "Looks like you dont have epel setup. Want to do that now (y/n): " |
|
read answer |
|
if [ ${answer} != "y" ]; then |
|
echo "Done! Now you can do: 'mkvirtualenv foo --python=python2.7'" |
|
exit |
|
fi |
|
rpm -Uvh http://mirror-fpt-telecom.fpt.net/fedora/epel/6/i386/epel-release-6-8.noarch.rpm |
|
fi |
|
echo "Done!" |
|
echo "source your bashrc then you can do: 'mkvirtualenv foo --python=python2.7'" |
This is tested and works on a fresh Rackspace cloud server using the CentOs 6.4 option, run as root and set executable.
profit