VirtualEnv, put simply, is an isolated working copy of Python which
allows you to work on a specific project without worry of affecting other projects

It enables multiple side-by-side installations of Python, one for each project.

It doesn’t actually install separate copies of Python, but it does provide a
clever way to keep different project environments isolated.

Installing VirtualEnv (CentOS):

Install a selection of development tools:

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.

Install Python 2.7.4

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=/opt/python2.7
make && make altinstall

Install distribute

wget 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
python2.7 setup.py install

Install/Configure virtualenv and virtualenvwrapper

wget https://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.9.1.tar.gz#md5=07e09df0adfca0b2d487e39a4bf2270a
tar -xvzf virtualenv-1.9.1.tar.gz 
python virtualenv-1.9.1/setup.py install
wget https://pypi.python.org/packages/source/v/virtualenvwrapper/virtualenvwrapper-4.0.tar.gz#md5=78df3b40735e959479d9de34e4b8ba15
tar -xvzf virtualenvwrapper-*
python virtualenvwrapper-4.0/setup.py install
echo 'export WORKON_HOME=~/Envs' >> .bashrc # Change this directory if you don't like it
. $HOME/.bashrc
mkdir -p $WORKON_HOME
echo '. /usr/bin/virtualenvwrapper.sh' >> .bashrc
. $HOME/.bashrc

You can now run commands like:

mkvirtualenv foo --python2.7

This will give you a clean python2.7 environment to work on.

  • No labels