Python is an excellent language to learn, for DBA’s who want to automate all the repetitive tasks, they need to perform. Once you start using python it is likely that you want to setup multiple environments with different versions of Python and libraries, based on the project you are working on. Virtualenv is a tool to create isolated python environments.
Below are the steps that i followed, to install a brand new working Python 2.7.6 environment with the following packages.
SQLAlchemy - Object Relational Mapper and SQL Toolkit for Python numpy - Fundamental package for scientific computing matplotlib - Python 2D plotting library ipython - Interactive Python Shell pandas - Python Data Analysis Library Flask - An easy to use Python Lightweight Micro Framework
This installation is performed on Ubuntu Linux, and i have already installed the libsqlite3-dev package and the oracle instant client.
Install Python 2.7.6
Download Python-2.7.6.tgz from http://www.python.org/getit
Install python 2.7.6 to your directory of choice.
tar -xvf Python-2.7.6.tgz cd Python-2.7.6/ ./configure --prefix=/u01/Rk/Apps/Python/Python276 make make install
Now you have python 2.7.6 installed into the /u01/Rk/Apps/Python/Python276 directory. (You will have a python binary in /u01/Rk/Apps/Python/Python276/bin)
curl -O https://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.11.1.tar.gz
tar -xzvf virtualenv-1.11.1.tar.gz cd virtualenv-1.11.1/ /u01/Rk/Apps/Python/Python276/bin/python virtualenv.py /u01/Rk/Apps/Python/p276env1
Activate the virtualenv
Install the additional Python Modules you need
pip install SQLAlchemy pip install numpy pip install matplotlib pip install ipython pip install pyzmq pip install tornado pip install jinja2 pip install pandas pip install Flask pip install Flask-SQLAlchemy
Ensure that the oracle instant client is installed, and the environment variables ORACLE_HOME and LD_LIBRARY_PATH are setup correctly.
Download cx_Oracle (a python extension module that allows access to oracle.) source from from http://cx-oracle.sourceforge.net/
tar -xzvf cx_Oracle-5.1.2.tar.gz cd cx_Oracle-5.1.2/ python setup.py install
Setup an alias (In your .bash_profile) to simplify invoking the virtualenv every time you want to use it.
alias p276env1='. /u01/Rk/Apps/Python/p276env1/bin/activate'
Now, anytime you want to execute a python program in this environment, you can invoke the Linux command line and